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.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.util.WorldUtils;
|
||||
import techreborn.blocks.machine.tier1.BlockPlayerDetector;
|
||||
import techreborn.blocks.machine.tier1.BlockPlayerDetector.PlayerDetectorType;
|
||||
import techreborn.blocks.machine.tier1.PlayerDetectorBlock;
|
||||
import techreborn.blocks.machine.tier1.PlayerDetectorBlock.PlayerDetectorType;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.init.TRContent;
|
||||
|
@ -62,7 +62,7 @@ public class PlayerDectectorBlockEntity extends PowerAcceptorBlockEntity impleme
|
|||
if (canUseEnergy(TechRebornConfig.playerDetectorEuPerTick)) {
|
||||
for (PlayerEntity player : world.getPlayers()) {
|
||||
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
|
||||
redstone = true;
|
||||
} else if (type == PlayerDetectorType.OTHERS) {// Others
|
||||
|
|
|
@ -88,34 +88,30 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
// TileMachineBase
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (world == null || world.isClient) {
|
||||
public boolean isLocked() {
|
||||
return lockedItemStack != ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public void setLocked(boolean value) {
|
||||
if (isLocked() == value) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
if (inventory.hasChanged()) {
|
||||
// Only set lockedItem in response to user input
|
||||
ItemStack stack = getStoredStack().copy();
|
||||
stack.setCount(1);
|
||||
lockedItemStack = value ? stack : ItemStack.EMPTY;
|
||||
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() {
|
||||
|
@ -154,10 +150,6 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
|||
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
|
||||
public ItemStack getDisplayedStack() {
|
||||
if (!isLocked()) {
|
||||
|
@ -239,15 +231,6 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
|||
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() {
|
||||
return storeItemStack.getCount() + inventory.getStack(OUTPUT_SLOT).getCount();
|
||||
}
|
||||
|
@ -256,12 +239,46 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
|||
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
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
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));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -325,57 +342,6 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
|||
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
|
||||
public void onBreak(World world, PlayerEntity playerEntity, BlockPos blockPos, BlockState blockState) {
|
||||
super.onBreak(world, playerEntity, blockPos, blockState);
|
||||
|
@ -411,60 +377,72 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
|||
// Inventory gets dropped automatically
|
||||
}
|
||||
|
||||
// The int methods are only for ContainerBuilder.sync()
|
||||
private int isLockedInt() {
|
||||
return isLocked() ? 1 : 0;
|
||||
}
|
||||
|
||||
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);
|
||||
@Override
|
||||
public boolean isValid(int slot, ItemStack stack) {
|
||||
if (slot == INPUT_SLOT && isLocked()) {
|
||||
return ItemUtils.isItemEqual(lockedItemStack, stack, true, true);
|
||||
}
|
||||
|
||||
|
||||
public CompoundTag getStoredStackNBT() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
getStoredStack().toTag(tag);
|
||||
return tag;
|
||||
if (slot == INPUT_SLOT && !(isEmpty() || isSameType(stack))) {
|
||||
return false;
|
||||
}
|
||||
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
|
||||
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity playerEntity) {
|
||||
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
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(int slot, ItemStack stack) {
|
||||
if (slot == INPUT_SLOT && isLocked()) {
|
||||
return ItemUtils.isItemEqual(lockedItemStack, stack, true, true);
|
||||
// The int methods are only for ContainerBuilder.sync()
|
||||
private int isLockedInt() {
|
||||
return isLocked() ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
if (slot == INPUT_SLOT && !(isEmpty() || isSameType(stack))) {
|
||||
return false;
|
||||
}
|
||||
return super.isValid(slot, stack);
|
||||
private void setLockedInt(int lockedInt) {
|
||||
setLocked(lockedInt == 1);
|
||||
}
|
||||
|
||||
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.utils.MessageIDs;
|
||||
|
||||
public class BlockPlayerDetector extends BlockMachineBase {
|
||||
public class PlayerDetectorBlock extends BlockMachineBase {
|
||||
|
||||
public static EnumProperty<PlayerDetectorType> TYPE;
|
||||
|
||||
public BlockPlayerDetector() {
|
||||
public PlayerDetectorBlock() {
|
||||
super(Block.Settings.of(Material.METAL).strength(2f, 2f), true);
|
||||
this.setDefaultState(this.getStateManager().getDefaultState().with(TYPE, PlayerDetectorType.ALL));
|
||||
}
|
||||
|
@ -70,8 +70,7 @@ public class BlockPlayerDetector extends BlockMachineBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPlaced(World worldIn, BlockPos pos, BlockState state, LivingEntity placer,
|
||||
ItemStack stack) {
|
||||
public void onPlaced(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
|
||||
super.onPlaced(worldIn, pos, state, placer, stack);
|
||||
BlockEntity blockEntity = worldIn.getBlockEntity(pos);
|
||||
if (blockEntity instanceof PlayerDectectorBlockEntity) {
|
||||
|
@ -142,18 +141,20 @@ public class BlockPlayerDetector extends BlockMachineBase {
|
|||
return null;
|
||||
}
|
||||
|
||||
// Block
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
TYPE = EnumProperty.of("type", PlayerDetectorType.class);
|
||||
builder.add(TYPE);
|
||||
}
|
||||
|
||||
// AbstractBlock
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean emitsRedstonePower(BlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public int getWeakRedstonePower(BlockState blockState, BlockView blockAccess, BlockPos pos, Direction side) {
|
||||
BlockEntity entity = blockAccess.getBlockEntity(pos);
|
||||
|
@ -163,6 +164,7 @@ public class BlockPlayerDetector extends BlockMachineBase {
|
|||
return 0;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public int getStrongRedstonePower(BlockState blockState, BlockView blockAccess, BlockPos pos, Direction side) {
|
||||
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.ItemFluidInfo;
|
||||
import reborncore.common.util.Tank;
|
||||
import reborncore.common.util.WorldUtils;
|
||||
import techreborn.blockentity.storage.fluid.TankUnitBaseBlockEntity;
|
||||
import techreborn.client.GuiType;
|
||||
import techreborn.init.TRContent;
|
||||
|
@ -86,18 +87,46 @@ public class TankUnitBlock extends BlockMachineBase {
|
|||
Tank tankInstance = tankUnitEntity.getTank();
|
||||
|
||||
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(tankInstance.getFluidInstance().getAmount().equalOrMoreThan(fluidValueAmount)){
|
||||
if(amountInTank.equalOrMoreThan(FluidValue.BUCKET)){
|
||||
|
||||
// Add to player inventory
|
||||
ItemStack returnStack = itemFluid.getFull(tankInstance.getFluid());
|
||||
returnStack.setCount(amount);
|
||||
playerIn.setStackInHand(Hand.MAIN_HAND, returnStack);
|
||||
// Amount to transfer is whatever is lower (stack count or tank level)
|
||||
int amountTransferBuckets = Math.min(amountInTank.getRawValue() / FluidValue.BUCKET.getRawValue(), stackInHand.getCount());
|
||||
|
||||
// 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
|
||||
tankInstance.getFluidInstance().setAmount(tankInstance.getFluidAmount().subtract(fluidValueAmount));
|
||||
tankInstance.getFluidInstance().setAmount(tankInstance.getFluidAmount().subtract(
|
||||
FluidValue.BUCKET.multiply(amountTransferBuckets)));
|
||||
}else{
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
|
@ -124,6 +153,18 @@ public class TankUnitBlock extends BlockMachineBase {
|
|||
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
|
||||
public IMachineGuiHandler getGui() {
|
||||
return GuiType.TANK_UNIT;
|
||||
|
|
|
@ -63,7 +63,7 @@ import techreborn.blocks.generator.GenericGeneratorBlock;
|
|||
import techreborn.blocks.lighting.BlockLamp;
|
||||
import techreborn.blocks.machine.tier0.IronAlloyFurnaceBlock;
|
||||
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.misc.*;
|
||||
import techreborn.blocks.storage.energy.*;
|
||||
|
@ -560,7 +560,7 @@ public class TRContent {
|
|||
CHUNK_LOADER(new GenericMachineBlock(GuiType.CHUNK_LOADER, ChunkLoaderBlockEntity::new)),
|
||||
LAMP_INCANDESCENT(new BlockLamp(4, 10, 8)),
|
||||
LAMP_LED(new BlockLamp(1, 1, 12)),
|
||||
PLAYER_DETECTOR(new BlockPlayerDetector());
|
||||
PLAYER_DETECTOR(new PlayerDetectorBlock());
|
||||
|
||||
public final String name;
|
||||
public final Block block;
|
||||
|
|
Loading…
Reference in a new issue