Merge remote-tracking branch 'origin/1.16' into 1.16
This commit is contained in:
commit
1c376d4aea
5 changed files with 197 additions and 164 deletions
|
@ -32,8 +32,8 @@ import net.minecraft.util.math.Direction;
|
||||||
import reborncore.api.IToolDrop;
|
import reborncore.api.IToolDrop;
|
||||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||||
import reborncore.common.util.WorldUtils;
|
import reborncore.common.util.WorldUtils;
|
||||||
import techreborn.blocks.machine.tier1.BlockPlayerDetector;
|
import techreborn.blocks.machine.tier1.PlayerDetectorBlock;
|
||||||
import techreborn.blocks.machine.tier1.BlockPlayerDetector.PlayerDetectorType;
|
import techreborn.blocks.machine.tier1.PlayerDetectorBlock.PlayerDetectorType;
|
||||||
import techreborn.config.TechRebornConfig;
|
import techreborn.config.TechRebornConfig;
|
||||||
import techreborn.init.TRBlockEntities;
|
import techreborn.init.TRBlockEntities;
|
||||||
import techreborn.init.TRContent;
|
import techreborn.init.TRContent;
|
||||||
|
@ -62,7 +62,7 @@ public class PlayerDectectorBlockEntity extends PowerAcceptorBlockEntity impleme
|
||||||
if (canUseEnergy(TechRebornConfig.playerDetectorEuPerTick)) {
|
if (canUseEnergy(TechRebornConfig.playerDetectorEuPerTick)) {
|
||||||
for (PlayerEntity player : world.getPlayers()) {
|
for (PlayerEntity player : world.getPlayers()) {
|
||||||
if (player.distanceTo(player) <= 256.0D) {
|
if (player.distanceTo(player) <= 256.0D) {
|
||||||
PlayerDetectorType type = world.getBlockState(pos).get(BlockPlayerDetector.TYPE);
|
PlayerDetectorType type = world.getBlockState(pos).get(PlayerDetectorBlock.TYPE);
|
||||||
if (type == PlayerDetectorType.ALL) {// ALL
|
if (type == PlayerDetectorType.ALL) {// ALL
|
||||||
redstone = true;
|
redstone = true;
|
||||||
} else if (type == PlayerDetectorType.OTHERS) {// Others
|
} else if (type == PlayerDetectorType.OTHERS) {// Others
|
||||||
|
|
|
@ -88,34 +88,30 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TileMachineBase
|
public boolean isLocked() {
|
||||||
@Override
|
return lockedItemStack != ItemStack.EMPTY;
|
||||||
public void tick() {
|
}
|
||||||
super.tick();
|
|
||||||
if (world == null || world.isClient) {
|
public void setLocked(boolean value) {
|
||||||
|
if (isLocked() == value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is an item in the input AND stored is less than max capacity
|
// Only set lockedItem in response to user input
|
||||||
if (!inventory.getStack(INPUT_SLOT).isEmpty() && !isFull()) {
|
ItemStack stack = getStoredStack().copy();
|
||||||
inventory.setStack(INPUT_SLOT, processInput(inventory.getStack(INPUT_SLOT)));
|
stack.setCount(1);
|
||||||
}
|
lockedItemStack = value ? stack : ItemStack.EMPTY;
|
||||||
|
|
||||||
// Fill output slot with goodies when stored has items and output count is less than max stack size
|
|
||||||
if (storeItemStack.getCount() > 0 && inventory.getStack(OUTPUT_SLOT).getCount() < getStoredStack().getMaxCount()) {
|
|
||||||
populateOutput();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == TRContent.StorageUnit.CREATIVE) {
|
|
||||||
if (!isFull() && !isEmpty()) {
|
|
||||||
fillToCapacity();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inventory.hasChanged()) {
|
|
||||||
syncWithAll();
|
syncWithAll();
|
||||||
inventory.resetChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean canModifyLocking() {
|
||||||
|
// Can always be unlocked
|
||||||
|
if (isLocked()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Can only lock if there is an item to lock
|
||||||
|
return !isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populateOutput() {
|
private void populateOutput() {
|
||||||
|
@ -154,10 +150,6 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
||||||
return storeItemStack.isEmpty() ? inventory.getStack(OUTPUT_SLOT) : storeItemStack;
|
return storeItemStack.isEmpty() ? inventory.getStack(OUTPUT_SLOT) : storeItemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStoredStack(ItemStack itemStack) {
|
|
||||||
storeItemStack = itemStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the ItemStack to be displayed to the player via UI / model
|
// Returns the ItemStack to be displayed to the player via UI / model
|
||||||
public ItemStack getDisplayedStack() {
|
public ItemStack getDisplayedStack() {
|
||||||
if (!isLocked()) {
|
if (!isLocked()) {
|
||||||
|
@ -239,15 +231,6 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
||||||
return getCurrentCapacity() == maxCapacity;
|
return getCurrentCapacity() == maxCapacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return getCurrentCapacity() == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canInsert(int index, ItemStack stack, @Nullable Direction direction) {
|
|
||||||
return super.canInsert(index, stack, direction) && (this.isEmpty() && !isLocked() || isSameType(stack));
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCurrentCapacity() {
|
public int getCurrentCapacity() {
|
||||||
return storeItemStack.getCount() + inventory.getStack(OUTPUT_SLOT).getCount();
|
return storeItemStack.getCount() + inventory.getStack(OUTPUT_SLOT).getCount();
|
||||||
}
|
}
|
||||||
|
@ -256,12 +239,46 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
||||||
return maxCapacity;
|
return maxCapacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Other stuff
|
// MachineBaseBlockEntity
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
super.tick();
|
||||||
|
if (world == null || world.isClient) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there is an item in the input AND stored is less than max capacity
|
||||||
|
if (!inventory.getStack(INPUT_SLOT).isEmpty() && !isFull()) {
|
||||||
|
inventory.setStack(INPUT_SLOT, processInput(inventory.getStack(INPUT_SLOT)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill output slot with goodies when stored has items and output count is less than max stack size
|
||||||
|
if (storeItemStack.getCount() > 0 && inventory.getStack(OUTPUT_SLOT).getCount() < getStoredStack().getMaxCount()) {
|
||||||
|
populateOutput();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == TRContent.StorageUnit.CREATIVE) {
|
||||||
|
if (!isFull() && !isEmpty()) {
|
||||||
|
fillToCapacity();
|
||||||
|
}
|
||||||
|
// void input items for creative storage (#2205)
|
||||||
|
inventory.setStack(INPUT_SLOT, ItemStack.EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inventory.hasChanged()) {
|
||||||
|
syncWithAll();
|
||||||
|
inventory.resetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canBeUpgraded() {
|
public boolean isEmpty() {
|
||||||
return false;
|
return getCurrentCapacity() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canInsert(int index, ItemStack stack, @Nullable Direction direction) {
|
||||||
|
return super.canInsert(index, stack, direction) && (this.isEmpty() && !isLocked() || isSameType(stack));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -325,57 +342,6 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
||||||
return tagCompound;
|
return tagCompound;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ItemHandlerProvider
|
|
||||||
@Override
|
|
||||||
public RebornInventory<StorageUnitBaseBlockEntity> getInventory() {
|
|
||||||
return inventory;
|
|
||||||
}
|
|
||||||
|
|
||||||
// IToolDrop
|
|
||||||
@Override
|
|
||||||
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
|
|
||||||
return getDropWithNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getDropWithNBT() {
|
|
||||||
ItemStack dropStack = new ItemStack(getBlockType(), 1);
|
|
||||||
final CompoundTag blockEntity = new CompoundTag();
|
|
||||||
|
|
||||||
this.toTag(blockEntity);
|
|
||||||
dropStack.setTag(new CompoundTag());
|
|
||||||
dropStack.getTag().put("blockEntity", blockEntity);
|
|
||||||
|
|
||||||
return dropStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
// IListInfoProvider
|
|
||||||
@Override
|
|
||||||
public void addInfo(final List<Text> info, final boolean isReal, boolean hasData) {
|
|
||||||
if (isReal || hasData) {
|
|
||||||
if (!this.isEmpty()) {
|
|
||||||
info.add(
|
|
||||||
new LiteralText(String.valueOf(this.getCurrentCapacity()))
|
|
||||||
.append(new TranslatableText("techreborn.tooltip.unit.divider"))
|
|
||||||
.append(this.getStoredStack().getName())
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
info.add(new TranslatableText("techreborn.tooltip.unit.empty"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
info.add(
|
|
||||||
new TranslatableText("techreborn.tooltip.unit.capacity")
|
|
||||||
.formatted(Formatting.GRAY)
|
|
||||||
.append(
|
|
||||||
new LiteralText(String.valueOf(this.getMaxCapacity()))
|
|
||||||
.formatted(Formatting.GOLD)
|
|
||||||
.append(" items (")
|
|
||||||
.append(String.valueOf(this.getMaxCapacity() / 64))
|
|
||||||
.append(")")
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBreak(World world, PlayerEntity playerEntity, BlockPos blockPos, BlockState blockState) {
|
public void onBreak(World world, PlayerEntity playerEntity, BlockPos blockPos, BlockState blockState) {
|
||||||
super.onBreak(world, playerEntity, blockPos, blockState);
|
super.onBreak(world, playerEntity, blockPos, blockState);
|
||||||
|
@ -411,60 +377,72 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
||||||
// Inventory gets dropped automatically
|
// Inventory gets dropped automatically
|
||||||
}
|
}
|
||||||
|
|
||||||
// The int methods are only for ContainerBuilder.sync()
|
@Override
|
||||||
private int isLockedInt() {
|
public boolean isValid(int slot, ItemStack stack) {
|
||||||
return isLocked() ? 1 : 0;
|
if (slot == INPUT_SLOT && isLocked()) {
|
||||||
}
|
return ItemUtils.isItemEqual(lockedItemStack, stack, true, true);
|
||||||
|
|
||||||
private void setLockedInt(int lockedInt) {
|
|
||||||
setLocked(lockedInt == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLocked() {
|
|
||||||
return lockedItemStack != ItemStack.EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocked(boolean value) {
|
|
||||||
if (isLocked() == value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only set lockedItem in response to user input
|
|
||||||
ItemStack stack = getStoredStack().copy();
|
|
||||||
stack.setCount(1);
|
|
||||||
lockedItemStack = value ? stack : ItemStack.EMPTY;
|
|
||||||
syncWithAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canModifyLocking() {
|
|
||||||
// Can always be unlocked
|
|
||||||
if (isLocked()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Can only lock if there is an item to lock
|
|
||||||
return !isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getStoredAmount() {
|
|
||||||
return this.getCurrentCapacity();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStoredAmount(int storedAmount) {
|
|
||||||
this.storedAmount = storedAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStoredStackFromNBT(CompoundTag tag) {
|
|
||||||
storeItemStack = ItemStack.fromTag(tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public CompoundTag getStoredStackNBT() {
|
if (slot == INPUT_SLOT && !(isEmpty() || isSameType(stack))) {
|
||||||
CompoundTag tag = new CompoundTag();
|
return false;
|
||||||
getStoredStack().toTag(tag);
|
}
|
||||||
return tag;
|
return super.isValid(slot, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBeUpgraded() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// InventoryProvider
|
||||||
|
@Override
|
||||||
|
public RebornInventory<StorageUnitBaseBlockEntity> getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
// IToolDrop
|
||||||
|
@Override
|
||||||
|
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
|
||||||
|
ItemStack dropStack = new ItemStack(getBlockType(), 1);
|
||||||
|
final CompoundTag blockEntity = new CompoundTag();
|
||||||
|
|
||||||
|
this.toTag(blockEntity);
|
||||||
|
dropStack.setTag(new CompoundTag());
|
||||||
|
dropStack.getOrCreateTag().put("blockEntity", blockEntity);
|
||||||
|
|
||||||
|
return dropStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
// IListInfoProvider
|
||||||
|
@Override
|
||||||
|
public void addInfo(final List<Text> info, final boolean isReal, boolean hasData) {
|
||||||
|
if (isReal || hasData) {
|
||||||
|
if (!this.isEmpty()) {
|
||||||
|
info.add(
|
||||||
|
new LiteralText(String.valueOf(this.getCurrentCapacity()))
|
||||||
|
.append(new TranslatableText("techreborn.tooltip.unit.divider"))
|
||||||
|
.append(this.getStoredStack().getName())
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
info.add(new TranslatableText("techreborn.tooltip.unit.empty"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
info.add(
|
||||||
|
new TranslatableText("techreborn.tooltip.unit.capacity")
|
||||||
|
.formatted(Formatting.GRAY)
|
||||||
|
.append(
|
||||||
|
new LiteralText(String.valueOf(this.getMaxCapacity()))
|
||||||
|
.formatted(Formatting.GOLD)
|
||||||
|
.append(" items (")
|
||||||
|
.append(String.valueOf(this.getMaxCapacity() / 64))
|
||||||
|
.append(")")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// BuiltScreenHandlerProvider
|
||||||
@Override
|
@Override
|
||||||
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity playerEntity) {
|
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity playerEntity) {
|
||||||
return new ScreenHandlerBuilder("chest").player(playerEntity.inventory).inventory().hotbar().addInventory()
|
return new ScreenHandlerBuilder("chest").player(playerEntity.inventory).inventory().hotbar().addInventory()
|
||||||
|
@ -479,18 +457,30 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
||||||
// Note that inventory is synced, and it gets the stack from that
|
// Note that inventory is synced, and it gets the stack from that
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// The int methods are only for ContainerBuilder.sync()
|
||||||
public boolean isValid(int slot, ItemStack stack) {
|
private int isLockedInt() {
|
||||||
if (slot == INPUT_SLOT && isLocked()) {
|
return isLocked() ? 1 : 0;
|
||||||
return ItemUtils.isItemEqual(lockedItemStack, stack, true, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setLockedInt(int lockedInt) {
|
||||||
if (slot == INPUT_SLOT && !(isEmpty() || isSameType(stack))) {
|
setLocked(lockedInt == 1);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return super.isValid(slot, stack);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getStoredAmount() {
|
||||||
|
return this.getCurrentCapacity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStoredAmount(int storedAmount) {
|
||||||
|
this.storedAmount = storedAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompoundTag getStoredStackNBT() {
|
||||||
|
CompoundTag tag = new CompoundTag();
|
||||||
|
getStoredStack().toTag(tag);
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStoredStackFromNBT(CompoundTag tag) {
|
||||||
|
storeItemStack = ItemStack.fromTag(tag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,11 +54,11 @@ import reborncore.common.util.StringUtils;
|
||||||
import techreborn.blockentity.machine.tier1.PlayerDectectorBlockEntity;
|
import techreborn.blockentity.machine.tier1.PlayerDectectorBlockEntity;
|
||||||
import techreborn.utils.MessageIDs;
|
import techreborn.utils.MessageIDs;
|
||||||
|
|
||||||
public class BlockPlayerDetector extends BlockMachineBase {
|
public class PlayerDetectorBlock extends BlockMachineBase {
|
||||||
|
|
||||||
public static EnumProperty<PlayerDetectorType> TYPE;
|
public static EnumProperty<PlayerDetectorType> TYPE;
|
||||||
|
|
||||||
public BlockPlayerDetector() {
|
public PlayerDetectorBlock() {
|
||||||
super(Block.Settings.of(Material.METAL).strength(2f, 2f), true);
|
super(Block.Settings.of(Material.METAL).strength(2f, 2f), true);
|
||||||
this.setDefaultState(this.getStateManager().getDefaultState().with(TYPE, PlayerDetectorType.ALL));
|
this.setDefaultState(this.getStateManager().getDefaultState().with(TYPE, PlayerDetectorType.ALL));
|
||||||
}
|
}
|
||||||
|
@ -70,8 +70,7 @@ public class BlockPlayerDetector extends BlockMachineBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlaced(World worldIn, BlockPos pos, BlockState state, LivingEntity placer,
|
public void onPlaced(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
|
||||||
ItemStack stack) {
|
|
||||||
super.onPlaced(worldIn, pos, state, placer, stack);
|
super.onPlaced(worldIn, pos, state, placer, stack);
|
||||||
BlockEntity blockEntity = worldIn.getBlockEntity(pos);
|
BlockEntity blockEntity = worldIn.getBlockEntity(pos);
|
||||||
if (blockEntity instanceof PlayerDectectorBlockEntity) {
|
if (blockEntity instanceof PlayerDectectorBlockEntity) {
|
||||||
|
@ -142,18 +141,20 @@ public class BlockPlayerDetector extends BlockMachineBase {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Block
|
|
||||||
@Override
|
@Override
|
||||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||||
TYPE = EnumProperty.of("type", PlayerDetectorType.class);
|
TYPE = EnumProperty.of("type", PlayerDetectorType.class);
|
||||||
builder.add(TYPE);
|
builder.add(TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AbstractBlock
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public boolean emitsRedstonePower(BlockState state) {
|
public boolean emitsRedstonePower(BlockState state) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public int getWeakRedstonePower(BlockState blockState, BlockView blockAccess, BlockPos pos, Direction side) {
|
public int getWeakRedstonePower(BlockState blockState, BlockView blockAccess, BlockPos pos, Direction side) {
|
||||||
BlockEntity entity = blockAccess.getBlockEntity(pos);
|
BlockEntity entity = blockAccess.getBlockEntity(pos);
|
||||||
|
@ -163,6 +164,7 @@ public class BlockPlayerDetector extends BlockMachineBase {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public int getStrongRedstonePower(BlockState blockState, BlockView blockAccess, BlockPos pos, Direction side) {
|
public int getStrongRedstonePower(BlockState blockState, BlockView blockAccess, BlockPos pos, Direction side) {
|
||||||
BlockEntity entity = blockAccess.getBlockEntity(pos);
|
BlockEntity entity = blockAccess.getBlockEntity(pos);
|
|
@ -43,6 +43,7 @@ import reborncore.common.fluid.FluidValue;
|
||||||
import reborncore.common.fluid.container.FluidInstance;
|
import reborncore.common.fluid.container.FluidInstance;
|
||||||
import reborncore.common.fluid.container.ItemFluidInfo;
|
import reborncore.common.fluid.container.ItemFluidInfo;
|
||||||
import reborncore.common.util.Tank;
|
import reborncore.common.util.Tank;
|
||||||
|
import reborncore.common.util.WorldUtils;
|
||||||
import techreborn.blockentity.storage.fluid.TankUnitBaseBlockEntity;
|
import techreborn.blockentity.storage.fluid.TankUnitBaseBlockEntity;
|
||||||
import techreborn.client.GuiType;
|
import techreborn.client.GuiType;
|
||||||
import techreborn.init.TRContent;
|
import techreborn.init.TRContent;
|
||||||
|
@ -86,18 +87,46 @@ public class TankUnitBlock extends BlockMachineBase {
|
||||||
Tank tankInstance = tankUnitEntity.getTank();
|
Tank tankInstance = tankUnitEntity.getTank();
|
||||||
|
|
||||||
if(new FluidInstance(fluid).isEmptyFluid()){
|
if(new FluidInstance(fluid).isEmptyFluid()){
|
||||||
|
FluidValue amountInTank = tankInstance.getFluidInstance().getAmount();
|
||||||
|
|
||||||
FluidValue fluidValueAmount = FluidValue.BUCKET.multiply(amount);
|
|
||||||
// If tank has content, fill up user's inventory
|
// If tank has content, fill up user's inventory
|
||||||
if(tankInstance.getFluidInstance().getAmount().equalOrMoreThan(fluidValueAmount)){
|
if(amountInTank.equalOrMoreThan(FluidValue.BUCKET)){
|
||||||
|
|
||||||
// Add to player inventory
|
// Amount to transfer is whatever is lower (stack count or tank level)
|
||||||
ItemStack returnStack = itemFluid.getFull(tankInstance.getFluid());
|
int amountTransferBuckets = Math.min(amountInTank.getRawValue() / FluidValue.BUCKET.getRawValue(), stackInHand.getCount());
|
||||||
returnStack.setCount(amount);
|
|
||||||
playerIn.setStackInHand(Hand.MAIN_HAND, returnStack);
|
// Remove items from player
|
||||||
|
stackInHand.decrement(amountTransferBuckets);
|
||||||
|
|
||||||
|
// Deposit into inventory, one by one (Stupid buckets)
|
||||||
|
for(int i = 0; i < amountTransferBuckets; i++){
|
||||||
|
ItemStack item = itemFluid.getFull(tankInstance.getFluid());
|
||||||
|
|
||||||
|
boolean didInsert;
|
||||||
|
|
||||||
|
ItemStack selectedStack = playerIn.getMainHandStack();
|
||||||
|
|
||||||
|
// Insert to select if it can, otherwise anywhere.
|
||||||
|
if(selectedStack.isEmpty()){
|
||||||
|
playerIn.setStackInHand(Hand.MAIN_HAND, item);
|
||||||
|
didInsert = true;
|
||||||
|
}else if(isSameItemFluid(item, selectedStack) && selectedStack.getCount() < selectedStack.getMaxCount()) {
|
||||||
|
selectedStack.increment(1);
|
||||||
|
didInsert = true;
|
||||||
|
}else {
|
||||||
|
didInsert = playerIn.inventory.insertStack(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// If didn't insert, just drop it.
|
||||||
|
if(!didInsert){
|
||||||
|
WorldUtils.dropItem(item,worldIn, playerIn.getBlockPos());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Remove from tank
|
// Remove from tank
|
||||||
tankInstance.getFluidInstance().setAmount(tankInstance.getFluidAmount().subtract(fluidValueAmount));
|
tankInstance.getFluidInstance().setAmount(tankInstance.getFluidAmount().subtract(
|
||||||
|
FluidValue.BUCKET.multiply(amountTransferBuckets)));
|
||||||
}else{
|
}else{
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
}
|
}
|
||||||
|
@ -124,6 +153,18 @@ public class TankUnitBlock extends BlockMachineBase {
|
||||||
return super.onUse(state, worldIn, pos, playerIn, hand, hitResult);
|
return super.onUse(state, worldIn, pos, playerIn, hand, hitResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isSameItemFluid(ItemStack i1, ItemStack i2){
|
||||||
|
// Only care about cells, buckets don't stack
|
||||||
|
if(!(i1.getItem() instanceof DynamicCellItem && i2.getItem() instanceof DynamicCellItem)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
DynamicCellItem dc1 = (DynamicCellItem)i1.getItem();
|
||||||
|
DynamicCellItem dc2 = (DynamicCellItem)i2.getItem();
|
||||||
|
|
||||||
|
return dc1.getFluid(i1).matchesType(dc2.getFluid(i2));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMachineGuiHandler getGui() {
|
public IMachineGuiHandler getGui() {
|
||||||
return GuiType.TANK_UNIT;
|
return GuiType.TANK_UNIT;
|
||||||
|
|
|
@ -63,7 +63,7 @@ import techreborn.blocks.generator.GenericGeneratorBlock;
|
||||||
import techreborn.blocks.lighting.BlockLamp;
|
import techreborn.blocks.lighting.BlockLamp;
|
||||||
import techreborn.blocks.machine.tier0.IronAlloyFurnaceBlock;
|
import techreborn.blocks.machine.tier0.IronAlloyFurnaceBlock;
|
||||||
import techreborn.blocks.machine.tier0.IronFurnaceBlock;
|
import techreborn.blocks.machine.tier0.IronFurnaceBlock;
|
||||||
import techreborn.blocks.machine.tier1.BlockPlayerDetector;
|
import techreborn.blocks.machine.tier1.PlayerDetectorBlock;
|
||||||
import techreborn.blocks.machine.tier1.ResinBasinBlock;
|
import techreborn.blocks.machine.tier1.ResinBasinBlock;
|
||||||
import techreborn.blocks.misc.*;
|
import techreborn.blocks.misc.*;
|
||||||
import techreborn.blocks.storage.energy.*;
|
import techreborn.blocks.storage.energy.*;
|
||||||
|
@ -560,7 +560,7 @@ public class TRContent {
|
||||||
CHUNK_LOADER(new GenericMachineBlock(GuiType.CHUNK_LOADER, ChunkLoaderBlockEntity::new)),
|
CHUNK_LOADER(new GenericMachineBlock(GuiType.CHUNK_LOADER, ChunkLoaderBlockEntity::new)),
|
||||||
LAMP_INCANDESCENT(new BlockLamp(4, 10, 8)),
|
LAMP_INCANDESCENT(new BlockLamp(4, 10, 8)),
|
||||||
LAMP_LED(new BlockLamp(1, 1, 12)),
|
LAMP_LED(new BlockLamp(1, 1, 12)),
|
||||||
PLAYER_DETECTOR(new BlockPlayerDetector());
|
PLAYER_DETECTOR(new PlayerDetectorBlock());
|
||||||
|
|
||||||
public final String name;
|
public final String name;
|
||||||
public final Block block;
|
public final Block block;
|
||||||
|
|
Loading…
Reference in a new issue