This commit is contained in:
parent
a64c91f34c
commit
9617d511ca
@ -47,6 +47,8 @@ dependencies {
|
|||||||
|
|
||||||
modImplementation "net.earthcomputer:libstructure:${project.libstructure_version}"
|
modImplementation "net.earthcomputer:libstructure:${project.libstructure_version}"
|
||||||
include "net.earthcomputer:libstructure:${project.libstructure_version}"
|
include "net.earthcomputer:libstructure:${project.libstructure_version}"
|
||||||
|
|
||||||
|
compileOnly "org.jetbrains:annotations:${project.jetbrains_annotations_version}"
|
||||||
}
|
}
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
|
@ -21,3 +21,4 @@ org.gradle.jvmargs = -Xmx1G
|
|||||||
autoconfig_version = 3.2.0-unstable
|
autoconfig_version = 3.2.0-unstable
|
||||||
libstructure_version = 1.4.1
|
libstructure_version = 1.4.1
|
||||||
roughlyenoughitems_version = 5.1.0-unstable
|
roughlyenoughitems_version = 5.1.0-unstable
|
||||||
|
jetbrains_annotations_version = 19.0.0
|
||||||
|
@ -9,6 +9,7 @@ import net.minecraft.item.ItemGroup;
|
|||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.Rarity;
|
import net.minecraft.util.Rarity;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple Block
|
* Simple Block
|
||||||
@ -50,6 +51,7 @@ public class SimpleBlock extends Block {
|
|||||||
* @return Item Group
|
* @return Item Group
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("SameReturnValue")
|
@SuppressWarnings("SameReturnValue")
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
protected ItemGroup getItemGroup() {
|
protected ItemGroup getItemGroup() {
|
||||||
return EnergonRelics.ITEM_GROUP;
|
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
|
* Should The Block item be Added To An Item Group In A Non-Development Environment
|
||||||
* @return Should it Be Added
|
* @return Should it Be Added
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
protected boolean addToItemGroup() {
|
protected boolean addToItemGroup() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -66,6 +69,7 @@ public class SimpleBlock extends Block {
|
|||||||
* Should A Block Item Be Registered
|
* Should A Block Item Be Registered
|
||||||
* @return Should It Be Registered
|
* @return Should It Be Registered
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
protected boolean registerItem() {
|
protected boolean registerItem() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -74,6 +78,7 @@ public class SimpleBlock extends Block {
|
|||||||
* Get Max Stack Count
|
* Get Max Stack Count
|
||||||
* @return Max Stack Count
|
* @return Max Stack Count
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
protected int getMaxCount() {
|
protected int getMaxCount() {
|
||||||
return 64;
|
return 64;
|
||||||
}
|
}
|
||||||
@ -82,6 +87,7 @@ public class SimpleBlock extends Block {
|
|||||||
* Should The Item Rarity be Epic
|
* Should The Item Rarity be Epic
|
||||||
* @return Should It Be Epic
|
* @return Should It Be Epic
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
protected boolean isEpic() {
|
protected boolean isEpic() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.util.registry.RegistryKey;
|
import net.minecraft.util.registry.RegistryKey;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -37,6 +38,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
|
|||||||
* Give Propagated Action To This Block
|
* Give Propagated Action To This Block
|
||||||
* @param action Action
|
* @param action Action
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
public final void addPropagatedAction(Action.PropagatedAction action) {
|
public final void addPropagatedAction(Action.PropagatedAction action) {
|
||||||
if (isEnergyProvider()) {
|
if (isEnergyProvider()) {
|
||||||
handlePropagatedAction(action);
|
handlePropagatedAction(action);
|
||||||
@ -50,6 +52,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
|
|||||||
* @param network Network ID
|
* @param network Network ID
|
||||||
* @return If Is In Network
|
* @return If Is In Network
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
public final boolean isNetwork(int network) {
|
public final boolean isNetwork(int network) {
|
||||||
return isEnergyProvider() && EnergonRelics.NETWORK_CHIP_ITEM.getID(stack) == network;
|
return isEnergyProvider() && EnergonRelics.NETWORK_CHIP_ITEM.getID(stack) == network;
|
||||||
}
|
}
|
||||||
@ -59,6 +62,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
|
|||||||
* @param pos Position
|
* @param pos Position
|
||||||
* @return Is Within Distance
|
* @return Is Within Distance
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
public final boolean isWithinDistance(Vec3d pos) {
|
public final boolean isWithinDistance(Vec3d pos) {
|
||||||
return getPos().isWithinDistance(pos, HardcodedConfig.POWER_RANGE);
|
return getPos().isWithinDistance(pos, HardcodedConfig.POWER_RANGE);
|
||||||
}
|
}
|
||||||
@ -67,6 +71,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
|
|||||||
* Get Current Dimension
|
* Get Current Dimension
|
||||||
* @return Current Dimension
|
* @return Current Dimension
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
public RegistryKey<World> getRegistryKey() {
|
public RegistryKey<World> getRegistryKey() {
|
||||||
return Objects.requireNonNull(getWorld()).getRegistryKey();
|
return Objects.requireNonNull(getWorld()).getRegistryKey();
|
||||||
}
|
}
|
||||||
@ -96,6 +101,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
|
|||||||
* Should Behave As Energy Provider
|
* Should Behave As Energy Provider
|
||||||
* @return Is Energy Provider
|
* @return Is Energy Provider
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
public boolean isEnergyProvider() {
|
public boolean isEnergyProvider() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -104,6 +110,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
|
|||||||
* Override To Handle Propagated Action
|
* Override To Handle Propagated Action
|
||||||
* @param action Propagated Action
|
* @param action Propagated Action
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
protected void handlePropagatedAction(Action.PropagatedAction action) {
|
protected void handlePropagatedAction(Action.PropagatedAction action) {
|
||||||
if (!isEnergyProvider()) {
|
if (!isEnergyProvider()) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
@ -149,6 +156,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
|
|||||||
* @param world World
|
* @param world World
|
||||||
* @return Item Stack
|
* @return Item Stack
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
public ItemStack takeStack(World world) {
|
public ItemStack takeStack(World world) {
|
||||||
ItemStack newStack = stack.copy();
|
ItemStack newStack = stack.copy();
|
||||||
setEnergyProviderSource(world, getPos(), newStack, true);
|
setEnergyProviderSource(world, getPos(), newStack, true);
|
||||||
@ -162,6 +170,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
|
|||||||
* @param newStack Item Stack
|
* @param newStack Item Stack
|
||||||
* @param world World
|
* @param world World
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
public void placeStack(ItemStack newStack, World world) {
|
public void placeStack(ItemStack newStack, World world) {
|
||||||
setEnergyProviderSource(world, getPos(), newStack, false);
|
setEnergyProviderSource(world, getPos(), newStack, false);
|
||||||
stack = newStack.copy();
|
stack = newStack.copy();
|
||||||
@ -172,6 +181,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
|
|||||||
* Has Item Stack
|
* Has Item Stack
|
||||||
* @return Has Item Stack
|
* @return Has Item Stack
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
public boolean hasStack() {
|
public boolean hasStack() {
|
||||||
return !stack.isEmpty();
|
return !stack.isEmpty();
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import net.minecraft.nbt.CompoundTag;
|
|||||||
import net.minecraft.nbt.IntArrayTag;
|
import net.minecraft.nbt.IntArrayTag;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -35,7 +36,7 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
|
|||||||
* @param action Action
|
* @param action Action
|
||||||
* @return If It Was Sent
|
* @return If It Was Sent
|
||||||
*/
|
*/
|
||||||
protected boolean hasSent(Action.PropagatedAction action) {
|
protected final boolean hasSent(Action.PropagatedAction action) {
|
||||||
return sent.contains(action);
|
return sent.contains(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +44,7 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
|
|||||||
* Propagate Action To The Network's Energy Providers
|
* Propagate Action To The Network's Energy Providers
|
||||||
* @param action Propagated Action
|
* @param action Propagated Action
|
||||||
*/
|
*/
|
||||||
protected void propagateAction(Action.PropagatedAction action) {
|
protected final void propagateAction(Action.PropagatedAction action) {
|
||||||
sent.add(action);
|
sent.add(action);
|
||||||
|
|
||||||
totalCost = totalCost + action.amountOwed();
|
totalCost = totalCost + action.amountOwed();
|
||||||
@ -61,12 +62,12 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
|
|||||||
* Convert Action To A Propagated Action And Then Propagate It
|
* Convert Action To A Propagated Action And Then Propagate It
|
||||||
* @param action Action
|
* @param action Action
|
||||||
*/
|
*/
|
||||||
protected void addAction(Action action) {
|
protected final void addAction(Action action) {
|
||||||
propagateAction(new Action.PropagatedActionImpl(action, getWorld(), getPos(), getCachedState()));
|
propagateAction(new Action.PropagatedActionImpl(action, getWorld(), getPos(), getCachedState()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<EnergyTickable> startTick() {
|
public final List<EnergyTickable> startTick() {
|
||||||
sent.clear();
|
sent.clear();
|
||||||
|
|
||||||
List<EnergyTickable> list = new ArrayList<>(super.startTick());
|
List<EnergyTickable> list = new ArrayList<>(super.startTick());
|
||||||
@ -97,7 +98,7 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logicTick() {
|
public final void logicTick() {
|
||||||
super.logicTick();
|
super.logicTick();
|
||||||
assert getWorld() != null;
|
assert getWorld() != null;
|
||||||
getWorld().getProfiler().push("energyTick");
|
getWorld().getProfiler().push("energyTick");
|
||||||
@ -109,7 +110,8 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
|
|||||||
* Get Total Cost In Energon
|
* Get Total Cost In Energon
|
||||||
* @return Cost
|
* @return Cost
|
||||||
*/
|
*/
|
||||||
public long getTotalCost() {
|
@ApiStatus.Internal
|
||||||
|
public final long getTotalCost() {
|
||||||
return previousTotalCost;
|
return previousTotalCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,12 +135,14 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
|
|||||||
/**
|
/**
|
||||||
* Create And Propagate Actions
|
* Create And Propagate Actions
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
protected abstract void energyTick();
|
protected abstract void energyTick();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle If This Is In The Specified Network
|
* Toggle If This Is In The Specified Network
|
||||||
* @param network Network ID
|
* @param network Network ID
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
public void toggle(int network) {
|
public void toggle(int network) {
|
||||||
if (contains(network)) {
|
if (contains(network)) {
|
||||||
networks.removeAll(Collections.singletonList(network));
|
networks.removeAll(Collections.singletonList(network));
|
||||||
@ -153,6 +157,7 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
|
|||||||
* @param network Network ID
|
* @param network Network ID
|
||||||
* @return If It Contains This Block
|
* @return If It Contains This Block
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
public boolean contains(int network) {
|
public boolean contains(int network) {
|
||||||
return networks.contains(network);
|
return networks.contains(network);
|
||||||
}
|
}
|
||||||
|
@ -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.block.entity.core.EnergyProviderBlockEntity;
|
||||||
import com.thebrokenrail.energonrelics.api.energy.Action;
|
import com.thebrokenrail.energonrelics.api.energy.Action;
|
||||||
import net.minecraft.block.entity.BlockEntityType;
|
import net.minecraft.block.entity.BlockEntityType;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple Implementation Of A Energy Generator
|
* Simple Implementation Of A Energy Generator
|
||||||
@ -15,17 +16,17 @@ public abstract class EnergyGeneratorBlockEntity extends EnergyProviderBlockEnti
|
|||||||
private long energy = 0;
|
private long energy = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnergyProvider() {
|
public final boolean isEnergyProvider() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getEnergy() {
|
public final long getEnergy() {
|
||||||
return energy;
|
return energy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setEnergy(long value) {
|
public final void setEnergy(long value) {
|
||||||
if (value < 0) {
|
if (value < 0) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
@ -33,11 +34,12 @@ public abstract class EnergyGeneratorBlockEntity extends EnergyProviderBlockEnti
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handlePropagatedAction(Action.PropagatedAction action) {
|
protected final void handlePropagatedAction(Action.PropagatedAction action) {
|
||||||
super.handlePropagatedAction(action);
|
super.handlePropagatedAction(action);
|
||||||
handlePropagatedActionWithGenerator(action);
|
handlePropagatedActionWithGenerator(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
public abstract long getDisplayEnergy();
|
public abstract long getDisplayEnergy();
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ import net.minecraft.block.BlockState;
|
|||||||
import net.minecraft.state.property.Property;
|
import net.minecraft.state.property.Property;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action That Can Be Performed With Energy
|
* Action That Can Be Performed With Energy
|
||||||
@ -84,6 +85,7 @@ public class Action {
|
|||||||
/**
|
/**
|
||||||
* Simple Implementation Of A Propagated Action
|
* Simple Implementation Of A Propagated Action
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
public static class PropagatedActionImpl implements PropagatedAction {
|
public static class PropagatedActionImpl implements PropagatedAction {
|
||||||
private final Action action;
|
private final Action action;
|
||||||
private final World world;
|
private final World world;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.thebrokenrail.energonrelics.api.energy.tick;
|
package com.thebrokenrail.energonrelics.api.energy.tick;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -10,14 +12,17 @@ public interface EnergyTickable {
|
|||||||
* Start Tick
|
* Start Tick
|
||||||
* @return Other Objects To Tick
|
* @return Other Objects To Tick
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
List<EnergyTickable> startTick();
|
List<EnergyTickable> startTick();
|
||||||
/**
|
/**
|
||||||
* Logic Tick
|
* Logic Tick
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
void logicTick();
|
void logicTick();
|
||||||
/**
|
/**
|
||||||
* Get ID
|
* Get ID
|
||||||
* @return ID
|
* @return ID
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
String getID();
|
String getID();
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import com.thebrokenrail.energonrelics.EnergonRelics;
|
|||||||
import com.thebrokenrail.energonrelics.component.NetworkComponent;
|
import com.thebrokenrail.energonrelics.component.NetworkComponent;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -13,6 +14,7 @@ import java.util.Objects;
|
|||||||
/**
|
/**
|
||||||
* Energy Ticker
|
* Energy Ticker
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
public class EnergyTicker {
|
public class EnergyTicker {
|
||||||
private static final List<EnergyTickable> scheduled = new ArrayList<>();
|
private static final List<EnergyTickable> scheduled = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -184,10 +184,11 @@ public class NetworkComponent extends PersistentState {
|
|||||||
public List<EnergyProviderBlockEntity> getSources(World world, int id) {
|
public List<EnergyProviderBlockEntity> getSources(World world, int id) {
|
||||||
world.getProfiler().push("getSources");
|
world.getProfiler().push("getSources");
|
||||||
|
|
||||||
List<EnergyProviderBlockEntity> result;
|
List<EnergyProviderBlockEntity> result = getSourcesFromCache(world, id);
|
||||||
|
|
||||||
List<EnergyProviderBlockEntity> cacheResult = getSourcesFromCache(world, id);
|
if (result == null) {
|
||||||
result = Objects.requireNonNullElseGet(cacheResult, () -> getSourcesFromCacheMiss(world, id));
|
result = getSourcesFromCacheMiss(world, id);
|
||||||
|
}
|
||||||
|
|
||||||
world.getProfiler().pop();
|
world.getProfiler().pop();
|
||||||
return result;
|
return result;
|
||||||
|
Reference in New Issue
Block a user