mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
Merge remote-tracking branch 'origin/1.20.4' into 1.20.4
This commit is contained in:
commit
c866a404ea
20 changed files with 92 additions and 112 deletions
|
@ -34,7 +34,6 @@ import net.minecraft.world.level.block.LiquidBlock;
|
|||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.neoforge.common.util.LazyOptional;
|
||||
import net.neoforged.neoforge.fluids.FluidStack;
|
||||
import net.neoforged.neoforge.fluids.FluidType;
|
||||
import net.neoforged.neoforge.fluids.IFluidBlock;
|
||||
|
@ -73,7 +72,6 @@ public class TileEntityFluidCollector extends TileEntityBase implements ISharing
|
|||
return super.drain(resource, action);
|
||||
}
|
||||
};
|
||||
public final LazyOptional<IFluidHandler> lazyTank = LazyOptional.of(() -> this.tank);
|
||||
private int lastTankAmount;
|
||||
private int currentTime;
|
||||
private int lastCompare;
|
||||
|
@ -147,7 +145,7 @@ public class TileEntityFluidCollector extends TileEntityBase implements ISharing
|
|||
|
||||
@Override
|
||||
public IFluidHandler getFluidHandler(Direction facing) {
|
||||
return this.lazyTank;
|
||||
return this.tank;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,7 +22,6 @@ import net.minecraft.world.level.block.Blocks;
|
|||
import net.minecraft.world.level.block.MagmaBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.neoforge.common.util.LazyOptional;
|
||||
import net.neoforged.neoforge.energy.IEnergyStorage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
|
@ -26,11 +26,11 @@ import net.minecraft.world.level.block.entity.BlockEntity;
|
|||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.neoforged.neoforge.common.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.common.util.LazyOptional;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.items.IItemHandler;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TileEntityItemInterfaceHopping extends TileEntityItemInterface {
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class TileEntityItemInterfaceHopping extends TileEntityItemInterface {
|
|||
// }
|
||||
}
|
||||
|
||||
LazyOptional<IItemHandler> handler = tile.itemHandler.getNormalHandler();
|
||||
Optional<IItemHandler> handler = Optional.ofNullable(tile.itemHandler.getNormalHandler());
|
||||
handler.ifPresent(cap -> {
|
||||
for (int i = 0; i < cap.getSlots(); i++) {
|
||||
ItemStack left = cap.insertItem(i, item.getItem(), false);
|
||||
|
@ -111,7 +111,7 @@ public class TileEntityItemInterfaceHopping extends TileEntityItemInterface {
|
|||
|
||||
BlockEntity from = this.level.getBlockEntity(this.getBlockPos().relative(Direction.UP));
|
||||
if (from != null && !(from instanceof TileEntityItemInterface)) {
|
||||
LazyOptional<IItemHandler> normal = from.getCapability(Capabilities.ITEM_HANDLER, Direction.DOWN);
|
||||
IItemHandler normal = this.level.getCapability(Capabilities.ItemHandler.BLOCK, from.getBlockPos(), Direction.DOWN);
|
||||
|
||||
Object slotless = null;
|
||||
// TODO: [port] add back
|
||||
|
@ -132,7 +132,7 @@ public class TileEntityItemInterfaceHopping extends TileEntityItemInterface {
|
|||
if (this.level.isLoaded(toPos)) {
|
||||
BlockEntity to = this.level.getBlockEntity(toPos);
|
||||
if (to != null && !(to instanceof TileEntityItemInterface)) {
|
||||
LazyOptional<IItemHandler> normal = to.getCapability(Capabilities.ITEM_HANDLER, facing.getOpposite());
|
||||
IItemHandler normal = this.level.getCapability(Capabilities.ItemHandler.BLOCK, to.getBlockPos(), facing.getOpposite());
|
||||
|
||||
Object slotless = null;
|
||||
// TODO: [port] Add back
|
||||
|
|
|
@ -30,12 +30,12 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
|
|||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.neoforge.common.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.common.util.LazyOptional;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.energy.IEnergyStorage;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
@ -115,9 +115,9 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay {
|
|||
// TODO: [port] this is super hacky, review and fix up
|
||||
@Override
|
||||
public IEnergyStorage getEnergyStorage(Direction facing) {
|
||||
return LazyOptional.of(() -> this.energyStorages[facing == null
|
||||
? 0
|
||||
: facing.ordinal()]);
|
||||
return this.energyStorages[facing == null
|
||||
? 0
|
||||
: facing.ordinal()];
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -136,7 +136,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay {
|
|||
if (this.level.hasChunkAt(pos)) {
|
||||
BlockEntity tile = this.level.getBlockEntity(pos);
|
||||
if (tile != null && !(tile instanceof TileEntityLaserRelay)) {
|
||||
if (tile.getCapability(Capabilities.ENERGY, side.getOpposite()).isPresent()) {
|
||||
if (this.level.getCapability(Capabilities.EnergyStorage.BLOCK, tile.getBlockPos(), side.getOpposite()) != null) {
|
||||
this.receiversAround.put(side, tile);
|
||||
|
||||
BlockEntity oldTile = old.get(side);
|
||||
|
@ -179,7 +179,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay {
|
|||
|
||||
Direction opp = facing.getOpposite();
|
||||
if (tile != null) {
|
||||
Boolean received = tile.getCapability(Capabilities.ENERGY, opp).map(cap -> cap.receiveEnergy(maxTransfer, true) > 0).orElse(false);
|
||||
Boolean received = Optional.ofNullable(this.level.getCapability(Capabilities.EnergyStorage.BLOCK, tile.getBlockPos(), opp)).map(cap -> cap.receiveEnergy(maxTransfer, true) > 0).orElse(false);
|
||||
if (received) {
|
||||
totalReceiverAmount++;
|
||||
workedOnce = true;
|
||||
|
@ -213,7 +213,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay {
|
|||
if (!alreadyChecked.contains(tile.getBlockPos())) {
|
||||
alreadyChecked.add(tile.getBlockPos());
|
||||
if (theRelay != this || side != from) {
|
||||
transmitted += tile.getCapability(Capabilities.ENERGY, opp).map(cap -> {
|
||||
transmitted += Optional.ofNullable(this.level.getCapability(Capabilities.EnergyStorage.BLOCK, tile.getBlockPos(), opp)).map(cap -> {
|
||||
int trans = 0;
|
||||
int theoreticalReceived = cap.receiveEnergy(Math.min(amountPer, lowestCap), true);
|
||||
if (theoreticalReceived > 0) {
|
||||
|
|
|
@ -28,8 +28,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
|
|||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.neoforge.common.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.common.util.LazyOptional;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.fluids.FluidStack;
|
||||
import net.neoforged.neoforge.fluids.capability.IFluidHandler;
|
||||
|
||||
|
@ -37,6 +36,7 @@ import javax.annotation.Nonnull;
|
|||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
@ -112,7 +112,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay {
|
|||
super.serverTick();
|
||||
if (this.mode == Mode.INPUT_ONLY) {
|
||||
for (Direction side : this.handlersAround.keySet()) {
|
||||
WorldUtil.doFluidInteraction(this.handlersAround.get(side), this, side.getOpposite(), Integer.MAX_VALUE);
|
||||
WorldUtil.doFluidInteraction(this.level, this.handlersAround.get(side).getBlockPos(), this.getBlockPos(), side.getOpposite(), Integer.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay {
|
|||
if (this.level.hasChunkAt(pos)) {
|
||||
BlockEntity tile = this.level.getBlockEntity(pos);
|
||||
if (tile != null && !(tile instanceof TileEntityLaserRelay)) {
|
||||
if (tile.getCapability(Capabilities.FLUID_HANDLER, side.getOpposite()).isPresent()) {
|
||||
if (this.level.getCapability(Capabilities.FluidHandler.BLOCK, tile.getBlockPos(), side.getOpposite()) != null) {
|
||||
this.handlersAround.put(side, tile);
|
||||
|
||||
BlockEntity oldTile = old.get(side);
|
||||
|
@ -156,9 +156,9 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay {
|
|||
// TODO: [port] super hacky, find better way of handling this.
|
||||
@Override
|
||||
public IFluidHandler getFluidHandler(Direction facing) {
|
||||
return LazyOptional.of(() -> this.fluidHandlers[facing == null
|
||||
return this.fluidHandlers[facing == null
|
||||
? 0
|
||||
: facing.ordinal()]);
|
||||
: facing.ordinal()];
|
||||
}
|
||||
|
||||
private int transmitFluid(Direction from, FluidStack stack, IFluidHandler.FluidAction action) {
|
||||
|
@ -194,7 +194,8 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay {
|
|||
BlockEntity tile = theRelay.handlersAround.get(facing);
|
||||
Direction opp = facing.getOpposite();
|
||||
|
||||
boolean received = tile.getCapability(Capabilities.FLUID_HANDLER, opp).map(cap -> cap.fill(stack, IFluidHandler.FluidAction.SIMULATE) > 0).orElse(false);
|
||||
boolean received = Optional.ofNullable(this.level.getCapability(Capabilities.FluidHandler.BLOCK, tile.getBlockPos(), opp))
|
||||
.map(cap -> cap.fill(stack, IFluidHandler.FluidAction.SIMULATE) > 0).orElse(false);
|
||||
if (received) {
|
||||
totalReceiverAmount++;
|
||||
workedOnce = true;
|
||||
|
@ -225,7 +226,8 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay {
|
|||
if (!alreadyChecked.contains(tile.getBlockPos())) {
|
||||
alreadyChecked.add(tile.getBlockPos());
|
||||
if (theRelay != this || side != from) {
|
||||
transmitted += tile.getCapability(Capabilities.FLUID_HANDLER, opp).map(cap -> {
|
||||
transmitted += Optional.ofNullable(this.level.getCapability(Capabilities.FluidHandler.BLOCK, tile.getBlockPos(), opp))
|
||||
.map(cap -> {
|
||||
int trans = 0;
|
||||
FluidStack copy = stack.copy();
|
||||
copy.setAmount(amountPer);
|
||||
|
|
|
@ -31,8 +31,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
|
|||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.neoforge.common.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.common.util.LazyOptional;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.items.IItemHandler;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -92,7 +91,7 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay {
|
|||
if (this.level.hasChunkAt(pos)) {
|
||||
BlockEntity tile = this.level.getBlockEntity(pos);
|
||||
if (tile != null && !(tile instanceof TileEntityItemInterface) && !(tile instanceof TileEntityLaserRelay)) {
|
||||
LazyOptional<IItemHandler> itemHandler = tile.getCapability(Capabilities.ITEM_HANDLER, side.getOpposite());
|
||||
IItemHandler itemHandler = this.level.getCapability(Capabilities.ItemHandler.BLOCK, tile.getBlockPos(), side.getOpposite());
|
||||
|
||||
Object slotlessHandler = null;
|
||||
// TODO: [port] add this back maybe?
|
||||
|
|
|
@ -31,6 +31,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
|
|||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TileEntityLaserRelayItemAdvanced extends TileEntityLaserRelayItem implements IButtonReactor, MenuProvider {
|
||||
|
||||
|
@ -99,7 +100,7 @@ public class TileEntityLaserRelayItemAdvanced extends TileEntityLaserRelayItem i
|
|||
|
||||
private void addWhitelistSmart(boolean output) {
|
||||
for (SlotlessableItemHandlerWrapper handler : this.handlersAround.values()) {
|
||||
handler.getNormalHandler().ifPresent(itemHandler -> {
|
||||
Optional.ofNullable(handler.getNormalHandler()).ifPresent(itemHandler -> {
|
||||
for (int i = 0; i < itemHandler.getSlots(); i++) {
|
||||
ItemStack stack = itemHandler.getStackInSlot(i);
|
||||
if (!stack.isEmpty()) {
|
||||
|
|
|
@ -22,7 +22,6 @@ import net.minecraft.world.level.block.Blocks;
|
|||
import net.minecraft.world.level.block.LeavesBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.neoforge.common.util.LazyOptional;
|
||||
import net.neoforged.neoforge.energy.IEnergyStorage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -32,7 +31,6 @@ import java.util.List;
|
|||
public class TileEntityLeafGenerator extends TileEntityBase implements ISharingEnergyProvider, IEnergyDisplay {
|
||||
|
||||
public final CustomEnergyStorage storage = new CustomEnergyStorage(35000, 0, 450);
|
||||
public final LazyOptional<IEnergyStorage> lazyEnergy = LazyOptional.of(() -> this.storage);
|
||||
private int nextUseCounter;
|
||||
private int oldEnergy;
|
||||
|
||||
|
@ -140,6 +138,6 @@ public class TileEntityLeafGenerator extends TileEntityBase implements ISharingE
|
|||
|
||||
@Override
|
||||
public IEnergyStorage getEnergyStorage(Direction facing) {
|
||||
return this.lazyEnergy;
|
||||
return this.storage;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import net.minecraft.world.level.block.Block;
|
|||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.neoforge.common.util.LazyOptional;
|
||||
import net.neoforged.neoforge.energy.IEnergyStorage;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -41,7 +40,6 @@ public class TileEntityLongRangeBreaker extends TileEntityInventoryBase implemen
|
|||
public static final int RANGE = 8;
|
||||
public static final int ENERGY_USE = 5;
|
||||
public final CustomEnergyStorage storage = new CustomEnergyStorage(10000, 20, 0);
|
||||
public final LazyOptional<IEnergyStorage> lazyEnergy = LazyOptional.of(() -> this.storage);
|
||||
private int lastEnergy;
|
||||
private int currentTime;
|
||||
|
||||
|
@ -142,7 +140,7 @@ public class TileEntityLongRangeBreaker extends TileEntityInventoryBase implemen
|
|||
|
||||
@Override
|
||||
public IEnergyStorage getEnergyStorage(Direction facing) {
|
||||
return this.lazyEnergy;
|
||||
return this.storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -137,7 +137,7 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn
|
|||
} else if (!tile.isRedstonePowered) {
|
||||
|
||||
RecipeHolder<LiquidFuelRecipe> recipeHolder = tile.getRecipeForCurrentFluid();
|
||||
if (recipeHolder != null && tile.storage.getEnergyStored() < tile.storage.getMaxEnergyStored() && tile.tank.getFluidAmount() >= recipeHolder.getFuelAmount()) {
|
||||
if (recipeHolder != null && tile.storage.getEnergyStored() < tile.storage.getMaxEnergyStored() && tile.tank.getFluidAmount() >= recipeHolder.value().getFuelAmount()) {
|
||||
LiquidFuelRecipe recipe = recipeHolder.value();
|
||||
tile.fuelUsage = recipe.getFuelAmount();
|
||||
tile.currentEnergyProduce = recipe.getTotalEnergy() / recipe.getBurnTime();
|
||||
|
|
|
@ -17,8 +17,8 @@ import net.minecraft.core.Direction;
|
|||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.neoforge.common.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.common.capabilities.Capability;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.energy.IEnergyStorage;
|
||||
|
||||
public class TileEntityPhantomEnergyface extends TileEntityPhantomface implements ISharingEnergyProvider {
|
||||
|
||||
|
@ -45,7 +45,7 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement
|
|||
BlockEntity tile = this.level.getBlockEntity(this.boundPosition);
|
||||
if (tile != null && !(tile instanceof TileEntityLaserRelayEnergy)) {
|
||||
for (Direction facing : Direction.values()) {
|
||||
if (tile.getCapability(Capabilities.ENERGY, facing).isPresent()) {
|
||||
if (this.level.getCapability(Capabilities.EnergyStorage.BLOCK, tile.getBlockPos(), facing) != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -55,8 +55,14 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCapabilitySupported(Capability<?> capability) {
|
||||
return capability == Capabilities.ENERGY;
|
||||
public IEnergyStorage getEnergyStorage(Direction facing) {
|
||||
if (this.isBoundThingInRange()) {
|
||||
BlockEntity tile = this.level.getBlockEntity(this.getBoundPosition());
|
||||
if (tile != null) {
|
||||
return this.level.getCapability(Capabilities.EnergyStorage.BLOCK, this.getBoundPosition(), facing);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,8 +19,8 @@ import net.minecraft.core.Direction;
|
|||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.neoforge.common.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.common.capabilities.Capability;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.items.IItemHandler;
|
||||
|
||||
public class TileEntityPhantomItemface extends TileEntityPhantomface {
|
||||
|
||||
|
@ -52,7 +52,7 @@ public class TileEntityPhantomItemface extends TileEntityPhantomface {
|
|||
BlockEntity tile = this.level.getBlockEntity(this.getBoundPosition());
|
||||
if (tile != null) {
|
||||
for (Direction facing : Direction.values()) {
|
||||
if (tile.getCapability(Capabilities.ITEM_HANDLER, facing).isPresent()) {
|
||||
if (this.level.getCapability(Capabilities.ItemHandler.BLOCK, this.getBoundPosition(), facing) != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -62,8 +62,14 @@ public class TileEntityPhantomItemface extends TileEntityPhantomface {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCapabilitySupported(Capability<?> capability) {
|
||||
return capability == Capabilities.ITEM_HANDLER;
|
||||
public IItemHandler getItemHandler(Direction facing) {
|
||||
if (this.isBoundThingInRange()) {
|
||||
BlockEntity tile = this.level.getBlockEntity(this.getBoundPosition());
|
||||
if (tile != null) {
|
||||
return this.level.getCapability(Capabilities.ItemHandler.BLOCK, this.getBoundPosition(), facing);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,8 +17,8 @@ import net.minecraft.core.Direction;
|
|||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.neoforge.common.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.common.capabilities.Capability;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.fluids.capability.IFluidHandler;
|
||||
|
||||
public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements ISharingFluidHandler {
|
||||
|
||||
|
@ -42,10 +42,10 @@ public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements
|
|||
@Override
|
||||
public boolean isBoundThingInRange() {
|
||||
if (super.isBoundThingInRange()) {
|
||||
BlockEntity tile = this.level.getBlockEntity(this.boundPosition);
|
||||
BlockEntity tile = this.level.getBlockEntity(this.getBoundPosition());
|
||||
if (tile != null && !(tile instanceof TileEntityLaserRelayFluids)) {
|
||||
for (Direction facing : Direction.values()) {
|
||||
if (tile.getCapability(Capabilities.FLUID_HANDLER, facing).isPresent()) {
|
||||
if (this.level.getCapability(Capabilities.FluidHandler.BLOCK, this.getBoundPosition(), facing) != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -55,8 +55,14 @@ public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCapabilitySupported(Capability<?> capability) {
|
||||
return capability == Capabilities.FLUID_HANDLER;
|
||||
public IFluidHandler getFluidHandler(Direction facing) {
|
||||
if (this.isBoundThingInRange()) {
|
||||
BlockEntity tile = this.level.getBlockEntity(this.getBoundPosition());
|
||||
if (tile != null) {
|
||||
return this.level.getCapability(Capabilities.FluidHandler.BLOCK, this.getBoundPosition(), facing);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,7 +17,6 @@ import net.minecraft.world.level.Level;
|
|||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.neoforge.common.capabilities.Capability;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
|
@ -71,9 +70,4 @@ public class TileEntityPhantomRedstoneface extends TileEntityPhantomface {
|
|||
|
||||
super.onUpdateSent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCapabilitySupported(Capability<?> capability) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,21 +14,14 @@ import de.ellpeck.actuallyadditions.api.tile.IPhantomTile;
|
|||
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
||||
import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.neoforge.common.capabilities.Capability;
|
||||
import net.neoforged.neoforge.common.util.LazyOptional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class TileEntityPhantomface extends TileEntityInventoryBase implements IPhantomTile {
|
||||
public static final int RANGE = 16;
|
||||
|
@ -186,21 +179,6 @@ public abstract class TileEntityPhantomface extends TileEntityInventoryBase impl
|
|||
return this.range;
|
||||
}
|
||||
|
||||
protected abstract boolean isCapabilitySupported(Capability<?> capability);
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability, @Nullable Direction side) {
|
||||
if (this.isBoundThingInRange() && this.isCapabilitySupported(capability)) {
|
||||
BlockEntity tile = this.level.getBlockEntity(this.getBoundPosition());
|
||||
if (tile != null) {
|
||||
return tile.getCapability(capability, side);
|
||||
}
|
||||
}
|
||||
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComparatorStrength() {
|
||||
if (this.isBoundThingInRange()) {
|
||||
|
|
|
@ -20,19 +20,18 @@ import net.minecraft.world.item.ItemStack;
|
|||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.neoforge.common.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.common.util.LazyOptional;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.energy.IEnergyStorage;
|
||||
import net.neoforged.neoforge.items.IItemHandler;
|
||||
import net.neoforged.neoforge.items.wrapper.PlayerInvWrapper;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TileEntityPlayerInterface extends TileEntityBase implements IEnergyDisplay {
|
||||
|
||||
public static final int DEFAULT_RANGE = 32;
|
||||
private final CustomEnergyStorage storage = new CustomEnergyStorage(30000, 50, 0);
|
||||
public final LazyOptional<IEnergyStorage> lazyEnergy = LazyOptional.of(() -> this.storage);
|
||||
public UUID connectedPlayer;
|
||||
public String playerName;
|
||||
private IItemHandler playerHandler;
|
||||
|
@ -69,7 +68,7 @@ public class TileEntityPlayerInterface extends TileEntityBase implements IEnergy
|
|||
: new PlayerInvWrapper(player.getInventory());
|
||||
}
|
||||
|
||||
return LazyOptional.of(() -> this.playerHandler);
|
||||
return this.playerHandler;
|
||||
}
|
||||
|
||||
public static <T extends BlockEntity> void clientTick(Level level, BlockPos pos, BlockState state, T t) {
|
||||
|
@ -93,7 +92,8 @@ public class TileEntityPlayerInterface extends TileEntityBase implements IEnergy
|
|||
ItemStack slot = player.getInventory().getItem(i);
|
||||
if (StackUtil.isValid(slot) && slot.getCount() == 1) {
|
||||
|
||||
int received = slot.getCapability(Capabilities.ENERGY).map(cap -> cap.receiveEnergy(tile.storage.getEnergyStored(), false)).orElse(0);
|
||||
int received = Optional.ofNullable(slot.getCapability(Capabilities.EnergyStorage.ITEM))
|
||||
.map(cap -> cap.receiveEnergy(tile.storage.getEnergyStored(), false)).orElse(0);
|
||||
if (received > 0) {
|
||||
tile.storage.extractEnergyInternal(received, false);
|
||||
}
|
||||
|
@ -149,6 +149,6 @@ public class TileEntityPlayerInterface extends TileEntityBase implements IEnergy
|
|||
|
||||
@Override
|
||||
public IEnergyStorage getEnergyStorage(Direction facing) {
|
||||
return this.lazyEnergy;
|
||||
return this.storage;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import net.minecraft.world.entity.player.Inventory;
|
|||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.item.crafting.SmeltingRecipe;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
@ -34,7 +35,6 @@ import net.minecraft.world.level.block.Block;
|
|||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.neoforged.neoforge.common.util.LazyOptional;
|
||||
import net.neoforged.neoforge.energy.IEnergyStorage;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@ -50,7 +50,6 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements
|
|||
public static final int ENERGY_USE = 25;
|
||||
private static final int SMELT_TIME = 80;
|
||||
public final CustomEnergyStorage storage = new CustomEnergyStorage(30000, 150, 0);
|
||||
public final LazyOptional<IEnergyStorage> lazyEnergy = LazyOptional.of(() -> this.storage);
|
||||
public int firstSmeltTime;
|
||||
public int secondSmeltTime;
|
||||
public boolean isAutoSplit;
|
||||
|
@ -194,10 +193,10 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements
|
|||
}
|
||||
|
||||
public Optional<ItemStack> getOutputForInput(ItemStack stack) {
|
||||
return level.getServer().getRecipeManager().getRecipeFor(RecipeType.SMELTING, new SingleItem(stack), level).map(recipe -> recipe.getResultItem(this.level.registryAccess()));
|
||||
return level.getServer().getRecipeManager().getRecipeFor(RecipeType.SMELTING, new SingleItem(stack), level).map(recipe -> recipe.value().getResultItem(this.level.registryAccess()));
|
||||
}
|
||||
|
||||
public Optional<SmeltingRecipe> getRecipeForInput(ItemStack stack) {
|
||||
public Optional<RecipeHolder<SmeltingRecipe>> getRecipeForInput(ItemStack stack) {
|
||||
return level.getServer().getRecipeManager().getRecipeFor(RecipeType.SMELTING, new SingleItem(stack), level);
|
||||
}
|
||||
|
||||
|
@ -215,8 +214,8 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements
|
|||
ItemStack input = this.inv.getStackInSlot(theInput);
|
||||
ItemStack output = this.inv.getStackInSlot(theOutput);
|
||||
if (!input.isEmpty()) {
|
||||
Optional<SmeltingRecipe> recipe = getRecipeForInput(input);
|
||||
return recipe.map($ -> output.isEmpty() || ItemStack.isSameItem(output, $.getResultItem(this.level.registryAccess())) && output.getCount() <= output.getMaxStackSize() - $.getResultItem(this.level.registryAccess()).getCount()).orElse(false);
|
||||
Optional<RecipeHolder<SmeltingRecipe>> recipe = getRecipeForInput(input);
|
||||
return recipe.map($ -> output.isEmpty() || ItemStack.isSameItem(output, $.value().getResultItem(this.level.registryAccess())) && output.getCount() <= output.getMaxStackSize() - $.value().getResultItem(this.level.registryAccess()).getCount()).orElse(false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -250,7 +249,7 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements
|
|||
|
||||
@Override
|
||||
public IEnergyStorage getEnergyStorage(Direction facing) {
|
||||
return this.lazyEnergy;
|
||||
return this.storage;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
|
|
@ -17,7 +17,6 @@ import net.minecraft.nbt.CompoundTag;
|
|||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.neoforge.common.util.LazyOptional;
|
||||
import net.neoforged.neoforge.energy.IEnergyStorage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -31,7 +30,6 @@ public class TileEntityShockSuppressor extends TileEntityBase implements IEnergy
|
|||
public static final int RANGE = 5;
|
||||
|
||||
public CustomEnergyStorage storage = new CustomEnergyStorage(300000, 400, 0);
|
||||
public final LazyOptional<IEnergyStorage> lazyEnergy = LazyOptional.of(() -> this.storage);
|
||||
private int oldEnergy;
|
||||
|
||||
public TileEntityShockSuppressor(BlockPos pos, BlockState state) {
|
||||
|
@ -47,14 +45,14 @@ public class TileEntityShockSuppressor extends TileEntityBase implements IEnergy
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateCaps() {
|
||||
super.invalidateCaps();
|
||||
|
||||
if (!this.level.isClientSide) {
|
||||
SUPPRESSORS.remove(this);
|
||||
}
|
||||
}
|
||||
// @Override
|
||||
// public void invalidateCaps() {
|
||||
// super.invalidateCaps();
|
||||
//
|
||||
// if (!this.level.isClientSide) {
|
||||
// SUPPRESSORS.remove(this);
|
||||
// }
|
||||
// }
|
||||
|
||||
public static <T extends BlockEntity> void clientTick(Level level, BlockPos pos, BlockState state, T t) {
|
||||
if (t instanceof TileEntityShockSuppressor tile) {
|
||||
|
@ -100,6 +98,6 @@ public class TileEntityShockSuppressor extends TileEntityBase implements IEnergy
|
|||
|
||||
@Override
|
||||
public IEnergyStorage getEnergyStorage(Direction facing) {
|
||||
return this.lazyEnergy;
|
||||
return this.storage;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
|||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
@ -38,10 +39,8 @@ import net.minecraft.world.phys.BlockHitResult;
|
|||
import net.minecraft.world.phys.Vec3;
|
||||
import net.neoforged.neoforge.common.TierSortingRegistry;
|
||||
import net.neoforged.neoforge.common.util.FakePlayerFactory;
|
||||
import net.neoforged.neoforge.common.util.LazyOptional;
|
||||
import net.neoforged.neoforge.energy.IEnergyStorage;
|
||||
import net.neoforged.neoforge.fluids.IFluidBlock;
|
||||
import net.neoforged.neoforge.registries.BuiltInRegistries;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
@ -51,7 +50,6 @@ public class TileEntityVerticalDigger extends TileEntityInventoryBase implements
|
|||
public static final int ENERGY_USE_PER_BLOCK = 650;
|
||||
public static final int DEFAULT_RANGE = 2;
|
||||
public final CustomEnergyStorage storage = new CustomEnergyStorage(200000, 2000, 0);
|
||||
public final LazyOptional<IEnergyStorage> lazyEnergy = LazyOptional.of(() -> this.storage);
|
||||
public boolean onlyMineOres;
|
||||
public int checkX;
|
||||
public int checkY = -1;
|
||||
|
@ -210,7 +208,7 @@ public class TileEntityVerticalDigger extends TileEntityInventoryBase implements
|
|||
}
|
||||
|
||||
private boolean isBlacklisted(Block block) {
|
||||
String reg = BuiltInRegistries.BLOCK.getKey(block).toString();
|
||||
String reg = BuiltInRegistries.BLOCK.getKey(block).toString();
|
||||
if (!reg.isEmpty()) {
|
||||
for (String string : ConfigStringListValues.MINER_BLACKLIST.getValue()) {
|
||||
if (reg.equals(string)) {
|
||||
|
@ -250,7 +248,7 @@ public class TileEntityVerticalDigger extends TileEntityInventoryBase implements
|
|||
|
||||
@Override
|
||||
public IEnergyStorage getEnergyStorage(Direction facing) {
|
||||
return this.lazyEnergy;
|
||||
return this.storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -186,9 +186,9 @@ public final class WorldUtil {
|
|||
//Everything else
|
||||
try {
|
||||
FakePlayer fake = FakePlayerFactory.getMinecraft((ServerLevel) level);
|
||||
if (fake.connection == null) {
|
||||
fake.connection = new NetHandlerSpaghettiServer(fake);
|
||||
}
|
||||
// if (fake.connection == null) {
|
||||
// fake.connection = new NetHandlerSpaghettiServer(fake);
|
||||
// }
|
||||
//ItemStack heldBefore = fake.getMainHandItem();
|
||||
setHandItemWithoutAnnoyingSound(fake, InteractionHand.MAIN_HAND, stack.copy());
|
||||
BlockHitResult ray = new BlockHitResult(new Vec3(0.5, 0.5, 0.5), side.getOpposite(), offsetPos, true);
|
||||
|
|
Loading…
Reference in a new issue