Add Annotations
All checks were successful
EnergonRelics/pipeline/head This commit looks good

This commit is contained in:
TheBrokenRail 2020-08-05 21:59:47 -04:00
parent a64c91f34c
commit 9617d511ca
10 changed files with 49 additions and 13 deletions

View File

@ -47,6 +47,8 @@ dependencies {
modImplementation "net.earthcomputer:libstructure:${project.libstructure_version}"
include "net.earthcomputer:libstructure:${project.libstructure_version}"
compileOnly "org.jetbrains:annotations:${project.jetbrains_annotations_version}"
}
publishing {

View File

@ -21,3 +21,4 @@ org.gradle.jvmargs = -Xmx1G
autoconfig_version = 3.2.0-unstable
libstructure_version = 1.4.1
roughlyenoughitems_version = 5.1.0-unstable
jetbrains_annotations_version = 19.0.0

View File

@ -9,6 +9,7 @@ import net.minecraft.item.ItemGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.Rarity;
import net.minecraft.util.registry.Registry;
import org.jetbrains.annotations.ApiStatus;
/**
* Simple Block
@ -50,6 +51,7 @@ public class SimpleBlock extends Block {
* @return Item Group
*/
@SuppressWarnings("SameReturnValue")
@ApiStatus.OverrideOnly
protected ItemGroup getItemGroup() {
return EnergonRelics.ITEM_GROUP;
}
@ -58,6 +60,7 @@ public class SimpleBlock extends Block {
* Should The Block item be Added To An Item Group In A Non-Development Environment
* @return Should it Be Added
*/
@ApiStatus.OverrideOnly
protected boolean addToItemGroup() {
return true;
}
@ -66,6 +69,7 @@ public class SimpleBlock extends Block {
* Should A Block Item Be Registered
* @return Should It Be Registered
*/
@ApiStatus.OverrideOnly
protected boolean registerItem() {
return true;
}
@ -74,6 +78,7 @@ public class SimpleBlock extends Block {
* Get Max Stack Count
* @return Max Stack Count
*/
@ApiStatus.OverrideOnly
protected int getMaxCount() {
return 64;
}
@ -82,6 +87,7 @@ public class SimpleBlock extends Block {
* Should The Item Rarity be Epic
* @return Should It Be Epic
*/
@ApiStatus.OverrideOnly
protected boolean isEpic() {
return false;
}

View File

@ -20,6 +20,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import org.jetbrains.annotations.ApiStatus;
import java.util.Collections;
import java.util.List;
@ -37,6 +38,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
* Give Propagated Action To This Block
* @param action Action
*/
@ApiStatus.Internal
public final void addPropagatedAction(Action.PropagatedAction action) {
if (isEnergyProvider()) {
handlePropagatedAction(action);
@ -50,6 +52,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
* @param network Network ID
* @return If Is In Network
*/
@ApiStatus.Internal
public final boolean isNetwork(int network) {
return isEnergyProvider() && EnergonRelics.NETWORK_CHIP_ITEM.getID(stack) == network;
}
@ -59,6 +62,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
* @param pos Position
* @return Is Within Distance
*/
@ApiStatus.Internal
public final boolean isWithinDistance(Vec3d pos) {
return getPos().isWithinDistance(pos, HardcodedConfig.POWER_RANGE);
}
@ -67,6 +71,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
* Get Current Dimension
* @return Current Dimension
*/
@ApiStatus.Internal
public RegistryKey<World> getRegistryKey() {
return Objects.requireNonNull(getWorld()).getRegistryKey();
}
@ -96,6 +101,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
* Should Behave As Energy Provider
* @return Is Energy Provider
*/
@ApiStatus.OverrideOnly
public boolean isEnergyProvider() {
return false;
}
@ -104,6 +110,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
* Override To Handle Propagated Action
* @param action Propagated Action
*/
@ApiStatus.OverrideOnly
protected void handlePropagatedAction(Action.PropagatedAction action) {
if (!isEnergyProvider()) {
throw new UnsupportedOperationException();
@ -149,6 +156,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
* @param world World
* @return Item Stack
*/
@ApiStatus.Internal
public ItemStack takeStack(World world) {
ItemStack newStack = stack.copy();
setEnergyProviderSource(world, getPos(), newStack, true);
@ -162,6 +170,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
* @param newStack Item Stack
* @param world World
*/
@ApiStatus.Internal
public void placeStack(ItemStack newStack, World world) {
setEnergyProviderSource(world, getPos(), newStack, false);
stack = newStack.copy();
@ -172,6 +181,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
* Has Item Stack
* @return Has Item Stack
*/
@ApiStatus.Internal
public boolean hasStack() {
return !stack.isEmpty();
}

View File

@ -9,6 +9,7 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntArrayTag;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.ApiStatus;
import java.util.ArrayList;
import java.util.Collections;
@ -35,7 +36,7 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
* @param action Action
* @return If It Was Sent
*/
protected boolean hasSent(Action.PropagatedAction action) {
protected final boolean hasSent(Action.PropagatedAction action) {
return sent.contains(action);
}
@ -43,7 +44,7 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
* Propagate Action To The Network's Energy Providers
* @param action Propagated Action
*/
protected void propagateAction(Action.PropagatedAction action) {
protected final void propagateAction(Action.PropagatedAction action) {
sent.add(action);
totalCost = totalCost + action.amountOwed();
@ -61,12 +62,12 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
* Convert Action To A Propagated Action And Then Propagate It
* @param action Action
*/
protected void addAction(Action action) {
protected final void addAction(Action action) {
propagateAction(new Action.PropagatedActionImpl(action, getWorld(), getPos(), getCachedState()));
}
@Override
public List<EnergyTickable> startTick() {
public final List<EnergyTickable> startTick() {
sent.clear();
List<EnergyTickable> list = new ArrayList<>(super.startTick());
@ -97,7 +98,7 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
}
@Override
public void logicTick() {
public final void logicTick() {
super.logicTick();
assert getWorld() != null;
getWorld().getProfiler().push("energyTick");
@ -109,7 +110,8 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
* Get Total Cost In Energon
* @return Cost
*/
public long getTotalCost() {
@ApiStatus.Internal
public final long getTotalCost() {
return previousTotalCost;
}
@ -133,12 +135,14 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
/**
* Create And Propagate Actions
*/
@ApiStatus.OverrideOnly
protected abstract void energyTick();
/**
* Toggle If This Is In The Specified Network
* @param network Network ID
*/
@ApiStatus.Internal
public void toggle(int network) {
if (contains(network)) {
networks.removeAll(Collections.singletonList(network));
@ -153,6 +157,7 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
* @param network Network ID
* @return If It Contains This Block
*/
@ApiStatus.Internal
public boolean contains(int network) {
return networks.contains(network);
}

View File

@ -3,6 +3,7 @@ package com.thebrokenrail.energonrelics.api.block.entity.helper;
import com.thebrokenrail.energonrelics.api.block.entity.core.EnergyProviderBlockEntity;
import com.thebrokenrail.energonrelics.api.energy.Action;
import net.minecraft.block.entity.BlockEntityType;
import org.jetbrains.annotations.ApiStatus;
/**
* Simple Implementation Of A Energy Generator
@ -15,17 +16,17 @@ public abstract class EnergyGeneratorBlockEntity extends EnergyProviderBlockEnti
private long energy = 0;
@Override
public boolean isEnergyProvider() {
public final boolean isEnergyProvider() {
return true;
}
@Override
public long getEnergy() {
public final long getEnergy() {
return energy;
}
@Override
public void setEnergy(long value) {
public final void setEnergy(long value) {
if (value < 0) {
throw new UnsupportedOperationException();
}
@ -33,11 +34,12 @@ public abstract class EnergyGeneratorBlockEntity extends EnergyProviderBlockEnti
}
@Override
protected void handlePropagatedAction(Action.PropagatedAction action) {
protected final void handlePropagatedAction(Action.PropagatedAction action) {
super.handlePropagatedAction(action);
handlePropagatedActionWithGenerator(action);
}
@Override
@ApiStatus.OverrideOnly
public abstract long getDisplayEnergy();
}

View File

@ -4,6 +4,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.state.property.Property;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.ApiStatus;
/**
* Action That Can Be Performed With Energy
@ -84,6 +85,7 @@ public class Action {
/**
* Simple Implementation Of A Propagated Action
*/
@ApiStatus.Internal
public static class PropagatedActionImpl implements PropagatedAction {
private final Action action;
private final World world;

View File

@ -1,5 +1,7 @@
package com.thebrokenrail.energonrelics.api.energy.tick;
import org.jetbrains.annotations.ApiStatus;
import java.util.List;
/**
@ -10,14 +12,17 @@ public interface EnergyTickable {
* Start Tick
* @return Other Objects To Tick
*/
@ApiStatus.OverrideOnly
List<EnergyTickable> startTick();
/**
* Logic Tick
*/
@ApiStatus.OverrideOnly
void logicTick();
/**
* Get ID
* @return ID
*/
@ApiStatus.OverrideOnly
String getID();
}

View File

@ -4,6 +4,7 @@ import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.component.NetworkComponent;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.World;
import org.jetbrains.annotations.ApiStatus;
import java.util.ArrayList;
import java.util.Collections;
@ -13,6 +14,7 @@ import java.util.Objects;
/**
* Energy Ticker
*/
@ApiStatus.Internal
public class EnergyTicker {
private static final List<EnergyTickable> scheduled = new ArrayList<>();

View File

@ -184,10 +184,11 @@ public class NetworkComponent extends PersistentState {
public List<EnergyProviderBlockEntity> getSources(World world, int id) {
world.getProfiler().push("getSources");
List<EnergyProviderBlockEntity> result;
List<EnergyProviderBlockEntity> result = getSourcesFromCache(world, id);
List<EnergyProviderBlockEntity> cacheResult = getSourcesFromCache(world, id);
result = Objects.requireNonNullElseGet(cacheResult, () -> getSourcesFromCacheMiss(world, id));
if (result == null) {
result = getSourcesFromCacheMiss(world, id);
}
world.getProfiler().pop();
return result;