Tiered tank and storage blocks, GUI improvements, refactoring, cell nerf and misc organisation (#1932)
Tanks, storage blocks and variouse stuff. Thanks to Dimmerworld!!
This commit is contained in:
parent
2fc9557516
commit
9328c47bed
207 changed files with 1830 additions and 928 deletions
|
@ -1,257 +0,0 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import reborncore.api.IListInfoProvider;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TechStorageBaseBlockEntity extends MachineBaseBlockEntity
|
||||
implements InventoryProvider, IToolDrop, IListInfoProvider {
|
||||
|
||||
public final int maxCapacity;
|
||||
public final RebornInventory<TechStorageBaseBlockEntity> inventory;
|
||||
public ItemStack storedItem;
|
||||
|
||||
public TechStorageBaseBlockEntity(BlockEntityType<?> blockEntityTypeIn, String name, int maxCapacity) {
|
||||
super(blockEntityTypeIn);
|
||||
this.maxCapacity = maxCapacity;
|
||||
storedItem = ItemStack.EMPTY;
|
||||
inventory = new RebornInventory<>(3, name, maxCapacity, this);
|
||||
}
|
||||
|
||||
public void readWithoutCoords(CompoundTag tagCompound) {
|
||||
|
||||
storedItem = ItemStack.EMPTY;
|
||||
|
||||
if (tagCompound.contains("storedStack")) {
|
||||
storedItem = ItemStack.fromTag(tagCompound.getCompound("storedStack"));
|
||||
}
|
||||
|
||||
if (!storedItem.isEmpty()) {
|
||||
storedItem.setCount(Math.min(tagCompound.getInt("storedQuantity"), this.maxCapacity));
|
||||
}
|
||||
|
||||
inventory.read(tagCompound);
|
||||
}
|
||||
|
||||
public CompoundTag writeWithoutCoords(CompoundTag tagCompound) {
|
||||
if (!storedItem.isEmpty()) {
|
||||
ItemStack temp = storedItem.copy();
|
||||
if (storedItem.getCount() > storedItem.getMaxCount()) {
|
||||
temp.setCount(storedItem.getMaxCount());
|
||||
}
|
||||
tagCompound.put("storedStack", temp.toTag(new CompoundTag()));
|
||||
tagCompound.putInt("storedQuantity", Math.min(storedItem.getCount(), maxCapacity));
|
||||
} else {
|
||||
tagCompound.putInt("storedQuantity", 0);
|
||||
}
|
||||
inventory.write(tagCompound);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
public ItemStack getDropWithNBT() {
|
||||
CompoundTag blockEntity = new CompoundTag();
|
||||
ItemStack dropStack = new ItemStack(getBlockType(), 1);
|
||||
writeWithoutCoords(blockEntity);
|
||||
dropStack.setTag(new CompoundTag());
|
||||
dropStack.getTag().put("blockEntity", blockEntity);
|
||||
storedItem.setCount(0);
|
||||
inventory.setInvStack(1, ItemStack.EMPTY);
|
||||
syncWithAll();
|
||||
|
||||
return dropStack;
|
||||
}
|
||||
|
||||
public int getStoredCount() {
|
||||
return storedItem.getCount();
|
||||
}
|
||||
|
||||
public List<ItemStack> getContentDrops() {
|
||||
ArrayList<ItemStack> stacks = new ArrayList<>();
|
||||
|
||||
if (!getStoredItemType().isEmpty()) {
|
||||
if (!inventory.getInvStack(1).isEmpty()) {
|
||||
stacks.add(inventory.getInvStack(1));
|
||||
}
|
||||
int size = storedItem.getMaxCount();
|
||||
for (int i = 0; i < getStoredCount() / size; i++) {
|
||||
ItemStack droped = storedItem.copy();
|
||||
droped.setCount(size);
|
||||
stacks.add(droped);
|
||||
}
|
||||
if (getStoredCount() % size != 0) {
|
||||
ItemStack droped = storedItem.copy();
|
||||
droped.setCount(getStoredCount() % size);
|
||||
stacks.add(droped);
|
||||
}
|
||||
}
|
||||
|
||||
return stacks;
|
||||
}
|
||||
|
||||
// TileMachineBase
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (!world.isClient) {
|
||||
ItemStack outputStack = ItemStack.EMPTY;
|
||||
if (!inventory.getInvStack(1).isEmpty()) {
|
||||
outputStack = inventory.getInvStack(1);
|
||||
}
|
||||
if (!inventory.getInvStack(0).isEmpty()
|
||||
&& (storedItem.getCount() + outputStack.getCount()) < maxCapacity) {
|
||||
ItemStack inputStack = inventory.getInvStack(0);
|
||||
if (getStoredItemType().isEmpty()
|
||||
|| (storedItem.isEmpty() && ItemUtils.isItemEqual(inputStack, outputStack, true, true))) {
|
||||
|
||||
storedItem = inputStack;
|
||||
inventory.setInvStack(0, ItemStack.EMPTY);
|
||||
} else if (ItemUtils.isItemEqual(getStoredItemType(), inputStack, true, true)) {
|
||||
int reminder = maxCapacity - storedItem.getCount() - outputStack.getCount();
|
||||
if (inputStack.getCount() <= reminder) {
|
||||
setStoredItemCount(inputStack.getCount());
|
||||
inventory.setInvStack(0, ItemStack.EMPTY);
|
||||
} else {
|
||||
setStoredItemCount(maxCapacity - outputStack.getCount());
|
||||
inventory.getInvStack(0).decrement(reminder);
|
||||
}
|
||||
}
|
||||
markDirty();
|
||||
syncWithAll();
|
||||
}
|
||||
|
||||
if (!storedItem.isEmpty()) {
|
||||
if (outputStack.isEmpty()) {
|
||||
|
||||
ItemStack delivered = storedItem.copy();
|
||||
delivered.setCount(Math.min(storedItem.getCount(), delivered.getMaxCount()));
|
||||
storedItem.decrement(delivered.getCount());
|
||||
|
||||
if (storedItem.isEmpty()) {
|
||||
storedItem = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
inventory.setInvStack(1, delivered);
|
||||
markDirty();
|
||||
syncWithAll();
|
||||
} else if (ItemUtils.isItemEqual(storedItem, outputStack, true, true)
|
||||
&& outputStack.getCount() < outputStack.getMaxCount()) {
|
||||
|
||||
int wanted = Math.min(storedItem.getCount(),
|
||||
outputStack.getMaxCount() - outputStack.getCount());
|
||||
outputStack.setCount(outputStack.getCount() + wanted);
|
||||
storedItem.decrement(wanted);
|
||||
|
||||
if (storedItem.isEmpty()) {
|
||||
storedItem = ItemStack.EMPTY;
|
||||
}
|
||||
markDirty();
|
||||
syncWithAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(CompoundTag tagCompound) {
|
||||
super.fromTag(tagCompound);
|
||||
readWithoutCoords(tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tagCompound) {
|
||||
super.toTag(tagCompound);
|
||||
writeWithoutCoords(tagCompound);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
// ItemHandlerProvider
|
||||
@Override
|
||||
public RebornInventory<TechStorageBaseBlockEntity> getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
|
||||
return getDropWithNBT();
|
||||
}
|
||||
|
||||
// IListInfoProvider
|
||||
@Override
|
||||
public void addInfo(List<Text> info, boolean isReal, boolean hasData) {
|
||||
if (isReal || hasData) {
|
||||
int size = 0;
|
||||
String name = "of nothing";
|
||||
if (!storedItem.isEmpty()) {
|
||||
name = storedItem.getName().getString();
|
||||
size += storedItem.getCount();
|
||||
}
|
||||
if (!inventory.getInvStack(1).isEmpty()) {
|
||||
name = inventory.getInvStack(1).getName().getString();
|
||||
size += inventory.getInvStack(1).getCount();
|
||||
}
|
||||
info.add(new LiteralText(size + " " + name));
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getStoredItemType() {
|
||||
return storedItem.isEmpty() ? inventory.getInvStack(1) : storedItem;
|
||||
}
|
||||
|
||||
|
||||
public void setStoredItemCount(int amount) {
|
||||
storedItem.increment(amount);
|
||||
markDirty();
|
||||
}
|
||||
|
||||
public void setStoredItemType(ItemStack type, int amount) {
|
||||
storedItem = type;
|
||||
storedItem.setCount(amount);
|
||||
markDirty();
|
||||
}
|
||||
|
||||
public int getMaxStoredCount() {
|
||||
return maxCapacity;
|
||||
}
|
||||
}
|
|
@ -45,7 +45,7 @@ import reborncore.common.crafting.RebornRecipeType;
|
|||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.serialization.SerializationUtil;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
import techreborn.init.ModRecipes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity;
|
||||
package techreborn.blockentity.machine;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity;
|
||||
package techreborn.blockentity.machine.misc;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
@ -35,7 +35,7 @@ import net.minecraft.util.Tickable;
|
|||
import reborncore.api.IToolDrop;
|
||||
import reborncore.common.util.ChatUtils;
|
||||
import reborncore.common.util.StringUtils;
|
||||
import techreborn.blocks.BlockAlarm;
|
||||
import techreborn.blocks.misc.BlockAlarm;
|
||||
import techreborn.init.ModSounds;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.init.TRContent;
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity;
|
||||
package techreborn.blockentity.machine.misc;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
|
@ -33,7 +33,7 @@ import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
|||
import reborncore.common.crafting.RebornRecipe;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
|
|
@ -39,7 +39,7 @@ import techreborn.config.TechRebornConfig;
|
|||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
import techreborn.utils.FluidUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.fusionReactor;
|
||||
package techreborn.blockentity.machine.multiblock;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
|
@ -32,7 +32,7 @@ import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
|||
import reborncore.common.crafting.RebornRecipe;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
|
|
@ -35,9 +35,9 @@ import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
|||
import reborncore.common.multiblock.IMultiblockPart;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.MachineCasingBlockEntity;
|
||||
import techreborn.blocks.BlockMachineCasing;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.machine.multiblock.casing.MachineCasingBlockEntity;
|
||||
import techreborn.blocks.misc.BlockMachineCasing;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
|
|
@ -42,7 +42,7 @@ import techreborn.config.TechRebornConfig;
|
|||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
import techreborn.utils.FluidUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
|
|
@ -42,7 +42,7 @@ import techreborn.config.TechRebornConfig;
|
|||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
import techreborn.utils.FluidUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
|
|
@ -36,7 +36,7 @@ import techreborn.config.TechRebornConfig;
|
|||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
|
||||
public class VacuumFreezerBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity;
|
||||
package techreborn.blockentity.machine.multiblock.casing;
|
||||
|
||||
import reborncore.common.multiblock.MultiblockControllerBase;
|
||||
import reborncore.common.multiblock.rectangular.RectangularMultiblockBlockEntityBase;
|
|
@ -30,7 +30,7 @@ import reborncore.client.containerBuilder.builder.BuiltContainer;
|
|||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
|
|
@ -30,7 +30,7 @@ import reborncore.client.containerBuilder.builder.BuiltContainer;
|
|||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
|
|
@ -34,7 +34,7 @@ import techreborn.config.TechRebornConfig;
|
|||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
|
||||
public class ChemicalReactorBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import reborncore.client.containerBuilder.builder.BuiltContainer;
|
|||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
|
|
@ -30,7 +30,7 @@ import reborncore.client.containerBuilder.builder.BuiltContainer;
|
|||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
|
|
@ -36,7 +36,7 @@ import techreborn.init.ModRecipes;
|
|||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.items.ItemDynamicCell;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
|
||||
public class IndustrialElectrolyzerBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@ import net.minecraft.util.math.Direction;
|
|||
import reborncore.api.IToolDrop;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.util.WorldUtils;
|
||||
import techreborn.blocks.tier1.BlockPlayerDetector;
|
||||
import techreborn.blocks.tier1.BlockPlayerDetector.PlayerDetectorType;
|
||||
import techreborn.blocks.machine.tier1.BlockPlayerDetector;
|
||||
import techreborn.blocks.machine.tier1.BlockPlayerDetector.PlayerDetectorType;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
|
|
@ -33,7 +33,7 @@ import techreborn.api.recipe.ScrapboxRecipeCrafter;
|
|||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
|
||||
public class ScrapboxinatorBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import reborncore.client.containerBuilder.builder.BuiltContainer;
|
|||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
|
|
@ -30,7 +30,7 @@ import reborncore.client.containerBuilder.builder.BuiltContainer;
|
|||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.init.TRContent;
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier3;
|
||||
|
||||
import reborncore.common.fluid.FluidValue;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
public class CreativeQuantumTankBlockEntity extends QuantumTankBlockEntity {
|
||||
|
||||
public CreativeQuantumTankBlockEntity() {
|
||||
super(TRBlockEntities.CREATIVE_QUANTUM_TANK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (!tank.isEmpty() && !tank.isFull()) {
|
||||
tank.setFluidAmount(FluidValue.INFINITE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int slotTransferSpeed() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fluidTransferAmount() {
|
||||
return 10000;
|
||||
}
|
||||
}
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity;
|
||||
package techreborn.blockentity.machine.tier3;
|
||||
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
@ -35,6 +35,7 @@ import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
|||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
|
@ -1,151 +0,0 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier3;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import reborncore.api.IListInfoProvider;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.fluid.FluidValue;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.Tank;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.utils.FluidUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class QuantumTankBlockEntity extends MachineBaseBlockEntity
|
||||
implements InventoryProvider, IToolDrop, IListInfoProvider, IContainerProvider {
|
||||
|
||||
public Tank tank = new Tank("QuantumTankBlockEntity", FluidValue.INFINITE, this);
|
||||
public RebornInventory<QuantumTankBlockEntity> inventory = new RebornInventory<>(3, "QuantumTankBlockEntity", 64, this);
|
||||
|
||||
public QuantumTankBlockEntity(){
|
||||
this(TRBlockEntities.QUANTUM_TANK);
|
||||
}
|
||||
|
||||
public QuantumTankBlockEntity(BlockEntityType<?> blockEntityTypeIn) {
|
||||
super(blockEntityTypeIn);
|
||||
}
|
||||
|
||||
public void readWithoutCoords(final CompoundTag tagCompound) {
|
||||
tank.read(tagCompound);
|
||||
}
|
||||
|
||||
public CompoundTag writeWithoutCoords(final CompoundTag tagCompound) {
|
||||
tank.write(tagCompound);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
public ItemStack getDropWithNBT() {
|
||||
final CompoundTag blockEntity = new CompoundTag();
|
||||
final ItemStack dropStack = TRContent.Machine.QUANTUM_TANK.getStack();
|
||||
this.writeWithoutCoords(blockEntity);
|
||||
dropStack.setTag(new CompoundTag());
|
||||
dropStack.getTag().put("blockEntity", blockEntity);
|
||||
return dropStack;
|
||||
}
|
||||
|
||||
// TileMachineBase
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (!world.isClient) {
|
||||
if (FluidUtils.drainContainers(tank, inventory, 0, 1)
|
||||
|| FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluid())) {
|
||||
this.syncWithAll();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(final CompoundTag tagCompound) {
|
||||
super.fromTag(tagCompound);
|
||||
readWithoutCoords(tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(final CompoundTag tagCompound) {
|
||||
super.toTag(tagCompound);
|
||||
writeWithoutCoords(tagCompound);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
// ItemHandlerProvider
|
||||
@Override
|
||||
public RebornInventory<QuantumTankBlockEntity> getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(final PlayerEntity entityPlayer) {
|
||||
return this.getDropWithNBT();
|
||||
}
|
||||
|
||||
// IListInfoProvider
|
||||
@Override
|
||||
public void addInfo(final List<Text> info, final boolean isReal, boolean hasData) {
|
||||
if (isReal | hasData) {
|
||||
if (!this.tank.getFluidInstance().isEmpty()) {
|
||||
info.add(new LiteralText(this.tank.getFluidAmount() + " of " + this.tank.getFluid()));
|
||||
} else {
|
||||
info.add(new LiteralText("Empty"));
|
||||
}
|
||||
}
|
||||
info.add(new LiteralText("Capacity " + this.tank.getCapacity()));
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("quantumtank").player(player.inventory).inventory().hotbar()
|
||||
.addInventory().blockEntity(this).fluidSlot(0, 80, 17).outputSlot(1, 80, 53)
|
||||
.sync(tank).addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Tank getTank() {
|
||||
return tank;
|
||||
}
|
||||
}
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage;
|
||||
package techreborn.blockentity.storage.energy;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage;
|
||||
package techreborn.blockentity.storage.energy;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
|
@ -35,7 +35,7 @@ import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
|||
import reborncore.common.util.RebornInventory;
|
||||
import team.reborn.energy.Energy;
|
||||
import team.reborn.energy.EnergyTier;
|
||||
import techreborn.blocks.storage.EnergyStorageBlock;
|
||||
import techreborn.blocks.storage.energy.EnergyStorageBlock;
|
||||
|
||||
/**
|
||||
* Created by Rushmead
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage;
|
||||
package techreborn.blockentity.storage.energy;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage;
|
||||
package techreborn.blockentity.storage.energy;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage;
|
||||
package techreborn.blockentity.storage.energy;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage.idsu;
|
||||
package techreborn.blockentity.storage.energy.idsu;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.World;
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage.idsu;
|
||||
package techreborn.blockentity.storage.energy.idsu;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
@ -32,7 +32,7 @@ import reborncore.client.containerBuilder.builder.BuiltContainer;
|
|||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import team.reborn.energy.EnergySide;
|
||||
import team.reborn.energy.EnergyTier;
|
||||
import techreborn.blockentity.storage.EnergyStorageBlockEntity;
|
||||
import techreborn.blockentity.storage.energy.EnergyStorageBlockEntity;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.init.TRContent;
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage.lesu;
|
||||
package techreborn.blockentity.storage.energy.lesu;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage.lesu;
|
||||
package techreborn.blockentity.storage.energy.lesu;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
|
@ -33,8 +33,8 @@ import reborncore.client.containerBuilder.IContainerProvider;
|
|||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import team.reborn.energy.EnergyTier;
|
||||
import techreborn.blockentity.storage.EnergyStorageBlockEntity;
|
||||
import techreborn.blocks.storage.LapotronicSUBlock;
|
||||
import techreborn.blockentity.storage.energy.EnergyStorageBlockEntity;
|
||||
import techreborn.blocks.storage.energy.LapotronicSUBlock;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.init.TRContent;
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage.lesu;
|
||||
package techreborn.blockentity.storage.energy.lesu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package techreborn.blockentity.storage.fluid;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import reborncore.common.util.Tank;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.init.TRContent;
|
||||
|
||||
@Deprecated
|
||||
public class CreativeQuantumTankBlockEntity extends TankUnitBaseBlockEntity {
|
||||
|
||||
// Save
|
||||
public CreativeQuantumTankBlockEntity() {
|
||||
super(TRBlockEntities.CREATIVE_QUANTUM_TANK, TRContent.TankUnit.QUANTUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBreak(World world, PlayerEntity playerEntity, BlockPos blockPos, BlockState blockState) {
|
||||
inventory.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
|
||||
if (world.isClient()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Tank tank = this.getTank();
|
||||
|
||||
inventory.clear();
|
||||
|
||||
world.setBlockState(pos, TRContent.TankUnit.CREATIVE.block.getDefaultState());
|
||||
|
||||
TankUnitBaseBlockEntity tankEntity = (TankUnitBaseBlockEntity) world.getBlockEntity(pos);
|
||||
|
||||
tankEntity.setTank(tank);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package techreborn.blockentity.storage.fluid;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import reborncore.common.util.Tank;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.init.TRContent;
|
||||
|
||||
@Deprecated
|
||||
public class QuantumTankBlockEntity extends TankUnitBaseBlockEntity {
|
||||
|
||||
// Save
|
||||
public QuantumTankBlockEntity() {
|
||||
super(TRBlockEntities.QUANTUM_TANK, TRContent.TankUnit.QUANTUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBreak(World world, PlayerEntity playerEntity, BlockPos blockPos, BlockState blockState) {
|
||||
inventory.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
|
||||
if (world.isClient()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Tank tank = this.getTank();
|
||||
|
||||
ItemStack inputSlotStack = getInvStack(0).copy();
|
||||
ItemStack outputSlotStack = getInvStack(1).copy();
|
||||
inventory.clear();
|
||||
|
||||
world.setBlockState(pos, TRContent.TankUnit.QUANTUM.block.getDefaultState());
|
||||
|
||||
TankUnitBaseBlockEntity tankEntity = (TankUnitBaseBlockEntity) world.getBlockEntity(pos);
|
||||
|
||||
tankEntity.setTank(tank);
|
||||
|
||||
tankEntity.setInvStack(0, inputSlotStack);
|
||||
tankEntity.setInvStack(1, outputSlotStack);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
package techreborn.blockentity.storage.fluid;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Formatting;
|
||||
import reborncore.api.IListInfoProvider;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.fluid.FluidValue;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.StringUtils;
|
||||
import reborncore.common.util.Tank;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.utils.FluidUtils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements InventoryProvider, IToolDrop, IListInfoProvider, IContainerProvider {
|
||||
protected Tank tank;
|
||||
protected RebornInventory<TankUnitBaseBlockEntity> inventory = new RebornInventory<>(2, "TankInventory", 64, this);
|
||||
|
||||
private TRContent.TankUnit type;
|
||||
|
||||
public TankUnitBaseBlockEntity() {
|
||||
super(TRBlockEntities.TANK_UNIT);
|
||||
}
|
||||
|
||||
public TankUnitBaseBlockEntity(TRContent.TankUnit type) {
|
||||
super(TRBlockEntities.TANK_UNIT);
|
||||
configureEntity(type);
|
||||
}
|
||||
|
||||
|
||||
public TankUnitBaseBlockEntity(BlockEntityType<?> blockEntityTypeIn, TRContent.TankUnit type) {
|
||||
super(blockEntityTypeIn);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
private void configureEntity(TRContent.TankUnit type) {
|
||||
this.type = type;
|
||||
this.tank = new Tank("TankStorage", type.capacity, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if (world.isClient()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (FluidUtils.drainContainers(tank, inventory, 0, 1)
|
||||
|| FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluid())) {
|
||||
|
||||
if (type == TRContent.TankUnit.CREATIVE) {
|
||||
if (!tank.isEmpty() && !tank.isFull()) {
|
||||
tank.setFluidAmount(FluidValue.INFINITE);
|
||||
}
|
||||
}
|
||||
syncWithAll();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(final CompoundTag tagCompound) {
|
||||
super.fromTag(tagCompound);
|
||||
if (tagCompound.contains("unitType")) {
|
||||
this.type = TRContent.TankUnit.valueOf(tagCompound.getString("unitType"));
|
||||
configureEntity(type);
|
||||
tank.read(tagCompound);
|
||||
} else {
|
||||
// SAVE COMPAT
|
||||
if (tagCompound.contains("QuantumTankBlockEntity")) {
|
||||
this.type = TRContent.TankUnit.QUANTUM;
|
||||
Tank temp = new Tank("QuantumTankBlockEntity", type.capacity, this);
|
||||
temp.read(tagCompound);
|
||||
|
||||
// Set tank name to what it should be
|
||||
tank = new Tank("TankStorage", type.capacity, this);
|
||||
tank.setFluid(null, temp.getFluidInstance().copy());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(final CompoundTag tagCompound) {
|
||||
super.toTag(tagCompound);
|
||||
tagCompound.putString("unitType", this.type.name());
|
||||
tank.write(tagCompound);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// ItemHandlerProvider
|
||||
@Override
|
||||
public RebornInventory<TankUnitBaseBlockEntity> getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
// IListInfoProvider
|
||||
@Override
|
||||
public void addInfo(final List<Text> info, final boolean isReal, boolean hasData) {
|
||||
if (isReal || hasData) {
|
||||
if (!this.tank.getFluidInstance().isEmpty()) {
|
||||
info.add(new LiteralText(this.tank.getFluidAmount() + StringUtils.t("techreborn.tooltip.unit.divider") + this.tank.getFluid()));
|
||||
} else {
|
||||
info.add(new TranslatableText("techreborn.tooltip.unit.empty"));
|
||||
}
|
||||
}
|
||||
info.add(new LiteralText(Formatting.GRAY + StringUtils.t("techreborn.tooltip.unit.capacity") + ":" + Formatting.GOLD + this.tank.getCapacity() + " (" + this.tank.getCapacity().getRawValue() / 1000 + ")"));
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("tank").player(player.inventory).inventory().hotbar()
|
||||
.addInventory().blockEntity(this).fluidSlot(0, 100, 53).outputSlot(1, 140, 53)
|
||||
.sync(tank).addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Tank getTank() {
|
||||
return tank;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setTank(Tank tank) {
|
||||
this.tank.setFluid(null, tank.getFluidInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity playerEntity) {
|
||||
return getDropWithNBT();
|
||||
}
|
||||
}
|
|
@ -22,31 +22,44 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier3;
|
||||
package techreborn.blockentity.storage.item;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.init.TRContent;
|
||||
|
||||
public class CreativeQuantumChestBlockEntity extends QuantumChestBlockEntity {
|
||||
@Deprecated
|
||||
public class CreativeQuantumChestBlockEntity extends StorageUnitBaseBlockEntity {
|
||||
|
||||
public CreativeQuantumChestBlockEntity() {
|
||||
super(TRBlockEntities.CREATIVE_QUANTUM_CHEST);
|
||||
super(TRBlockEntities.CREATIVE_QUANTUM_CHEST, "QuantumChestBlockEntity", Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBreak(World world, PlayerEntity playerEntity, BlockPos blockPos, BlockState blockState) {
|
||||
super.inventory.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
ItemStack stack = inventory.getInvStack(1);
|
||||
if (!stack.isEmpty() && storedItem.isEmpty()) {
|
||||
stack.setCount(stack.getMaxCount());
|
||||
storedItem = stack.copy();
|
||||
if (world.isClient()) {
|
||||
return;
|
||||
}
|
||||
|
||||
storedItem.setCount(maxCapacity - storedItem.getMaxCount());
|
||||
}
|
||||
ItemStack storedStack = this.getAll();
|
||||
|
||||
@Override
|
||||
public int slotTransferSpeed() {
|
||||
return 1;
|
||||
this.clear();
|
||||
|
||||
world.setBlockState(pos, TRContent.StorageUnit.CREATIVE.block.getDefaultState());
|
||||
|
||||
StorageUnitBaseBlockEntity storageEntity = (StorageUnitBaseBlockEntity) world.getBlockEntity(pos);
|
||||
|
||||
if (!storedStack.isEmpty() && storageEntity != null) {
|
||||
storageEntity.setStoredStack(storedStack);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,24 +22,46 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity;
|
||||
package techreborn.blockentity.storage.item;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.init.TRContent;
|
||||
|
||||
public class DigitalChestBlockEntity extends TechStorageBaseBlockEntity implements IContainerProvider {
|
||||
@Deprecated
|
||||
public class DigitalChestBlockEntity extends StorageUnitBaseBlockEntity {
|
||||
|
||||
public DigitalChestBlockEntity() {
|
||||
super(TRBlockEntities.DIGITAL_CHEST, "DigitalChestBlockEntity", TechRebornConfig.digitalChestMaxStorage);
|
||||
super(TRBlockEntities.DIGITAL_CHEST, "DigitalChestBlockEntity", 32768);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("digitalchest").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).slot(0, 80, 24).outputSlot(1, 80, 64).addInventory().create(this, syncID);
|
||||
public void onBreak(World world, PlayerEntity playerEntity, BlockPos blockPos, BlockState blockState) {
|
||||
super.inventory.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (world.isClient()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack storedStack = this.getAll();
|
||||
ItemStack inputSlotStack = this.getInvStack(0).copy();
|
||||
|
||||
this.clear();
|
||||
|
||||
world.setBlockState(pos, TRContent.StorageUnit.INDUSTRIAL.block.getDefaultState());
|
||||
|
||||
StorageUnitBaseBlockEntity storageEntity = (StorageUnitBaseBlockEntity) world.getBlockEntity(pos);
|
||||
|
||||
if (!storedStack.isEmpty() && storageEntity != null) {
|
||||
storageEntity.setStoredStack(storedStack);
|
||||
storageEntity.setInvStack(0, inputSlotStack);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,31 +22,47 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier3;
|
||||
package techreborn.blockentity.storage.item;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import techreborn.blockentity.TechStorageBaseBlockEntity;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.init.TRContent;
|
||||
|
||||
public class QuantumChestBlockEntity extends TechStorageBaseBlockEntity implements IContainerProvider {
|
||||
@Deprecated
|
||||
public class QuantumChestBlockEntity extends StorageUnitBaseBlockEntity {
|
||||
|
||||
public QuantumChestBlockEntity() {
|
||||
this(TRBlockEntities.QUANTUM_CHEST);
|
||||
}
|
||||
|
||||
public QuantumChestBlockEntity(BlockEntityType<?> blockEntityType) {
|
||||
super(blockEntityType, "QuantumChestBlockEntity", TechRebornConfig.quantumChestMaxStorage);
|
||||
super(TRBlockEntities.QUANTUM_CHEST, "QuantumChestBlockEntity", Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("quantumchest").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).slot(0, 80, 24).outputSlot(1, 80, 64).addInventory().create(this, syncID);
|
||||
public void onBreak(World world, PlayerEntity playerEntity, BlockPos blockPos, BlockState blockState) {
|
||||
super.inventory.clear();
|
||||
super.onBreak(world, playerEntity, blockPos, blockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (world.isClient()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack storedStack = this.getAll();
|
||||
ItemStack inputSlotStack = this.getInvStack(0).copy();
|
||||
|
||||
this.clear();
|
||||
|
||||
world.setBlockState(pos, TRContent.StorageUnit.QUANTUM.block.getDefaultState());
|
||||
|
||||
StorageUnitBaseBlockEntity storageEntity = (StorageUnitBaseBlockEntity) world.getBlockEntity(pos);
|
||||
|
||||
if (!storedStack.isEmpty() && storageEntity != null) {
|
||||
storageEntity.setStoredStack(storedStack);
|
||||
storageEntity.setInvStack(0, inputSlotStack);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,384 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage.item;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import reborncore.api.IListInfoProvider;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.StringUtils;
|
||||
import reborncore.common.util.WorldUtils;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.init.TRContent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity
|
||||
implements InventoryProvider, IToolDrop, IListInfoProvider, IContainerProvider {
|
||||
|
||||
|
||||
// Inventory constants
|
||||
private static final int INPUT_SLOT = 0;
|
||||
private static final int OUTPUT_SLOT = 1;
|
||||
|
||||
protected RebornInventory<StorageUnitBaseBlockEntity> inventory;
|
||||
private int maxCapacity;
|
||||
|
||||
private boolean shouldUpdate = false;
|
||||
|
||||
private ItemStack storeItemStack;
|
||||
|
||||
private TRContent.StorageUnit type;
|
||||
|
||||
public StorageUnitBaseBlockEntity() {
|
||||
super(TRBlockEntities.STORAGE_UNIT);
|
||||
}
|
||||
|
||||
public StorageUnitBaseBlockEntity(TRContent.StorageUnit type) {
|
||||
super(TRBlockEntities.STORAGE_UNIT);
|
||||
configureEntity(type);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public StorageUnitBaseBlockEntity(BlockEntityType<?> blockEntityTypeIn, String name, int maxCapacity) {
|
||||
super(blockEntityTypeIn);
|
||||
this.maxCapacity = maxCapacity;
|
||||
storeItemStack = ItemStack.EMPTY;
|
||||
type = TRContent.StorageUnit.QUANTUM;
|
||||
inventory = new RebornInventory<>(3, name, maxCapacity, this);
|
||||
}
|
||||
|
||||
private void configureEntity(TRContent.StorageUnit type) {
|
||||
this.maxCapacity = type.capacity;
|
||||
storeItemStack = ItemStack.EMPTY;
|
||||
inventory = new RebornInventory<>(2, "ItemInventory", 64, this);
|
||||
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
// TileMachineBase
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (world.isClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// If there is an item in the input AND stored is less than max capacity
|
||||
if (!inventory.getInvStack(INPUT_SLOT).isEmpty() && !isFull()) {
|
||||
inventory.setInvStack(INPUT_SLOT, processInput(inventory.getInvStack(INPUT_SLOT)));
|
||||
|
||||
shouldUpdate = true;
|
||||
}
|
||||
|
||||
// Fill output slot with goodies when stored has items and output count is less than max stack size
|
||||
if (storeItemStack.getCount() > 0 && inventory.getInvStack(OUTPUT_SLOT).getCount() < getStoredStack().getMaxCount()) {
|
||||
populateOutput();
|
||||
|
||||
shouldUpdate = true;
|
||||
}
|
||||
|
||||
if (type == TRContent.StorageUnit.CREATIVE) {
|
||||
if (!isFull() && !isEmpty()) {
|
||||
fillToCapacity();
|
||||
shouldUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (shouldUpdate) {
|
||||
inventory.setChanged();
|
||||
markDirty();
|
||||
syncWithAll();
|
||||
|
||||
shouldUpdate = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void populateOutput() {
|
||||
// Set to storeItemStack to get the stack type
|
||||
ItemStack output = storeItemStack.copy();
|
||||
|
||||
int outputSlotCount = inventory.getInvStack(OUTPUT_SLOT).getCount();
|
||||
|
||||
// Set to current outputSlot count
|
||||
output.setCount(outputSlotCount);
|
||||
|
||||
// Calculate amount needed to fill stack in output slot
|
||||
int amountToFill = getStoredStack().getMaxCount() - outputSlotCount;
|
||||
|
||||
if (storeItemStack.getCount() >= amountToFill) {
|
||||
storeItemStack.decrement(amountToFill);
|
||||
|
||||
if (storeItemStack.isEmpty()) {
|
||||
storeItemStack = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
output.increment(amountToFill);
|
||||
} else {
|
||||
output.increment(storeItemStack.getCount());
|
||||
storeItemStack = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
inventory.setInvStack(OUTPUT_SLOT, output);
|
||||
}
|
||||
|
||||
private void addStoredItemCount(int amount) {
|
||||
storeItemStack.increment(amount);
|
||||
}
|
||||
|
||||
public ItemStack getStoredStack() {
|
||||
return storeItemStack.isEmpty() ? inventory.getInvStack(OUTPUT_SLOT) : storeItemStack;
|
||||
}
|
||||
|
||||
public ItemStack getAll() {
|
||||
ItemStack returnStack = ItemStack.EMPTY;
|
||||
|
||||
if (!isEmpty()) {
|
||||
returnStack = getStoredStack().copy();
|
||||
returnStack.setCount(getCurrentCapacity());
|
||||
}
|
||||
|
||||
return returnStack;
|
||||
}
|
||||
|
||||
public void setStoredStack(ItemStack itemStack) {
|
||||
storeItemStack = itemStack;
|
||||
}
|
||||
|
||||
public ItemStack processInput(ItemStack inputStack) {
|
||||
|
||||
boolean isSameStack = isSameType(inputStack);
|
||||
|
||||
if (storeItemStack == ItemStack.EMPTY && (isSameStack || getCurrentCapacity() == 0)) {
|
||||
// Check if storage is empty, NOT including the output slot
|
||||
storeItemStack = inputStack.copy();
|
||||
|
||||
if (inputStack.getCount() <= maxCapacity) {
|
||||
inputStack = ItemStack.EMPTY;
|
||||
} else {
|
||||
// Stack is higher than capacity
|
||||
storeItemStack.setCount(maxCapacity);
|
||||
inputStack.decrement(maxCapacity);
|
||||
}
|
||||
} else if (isSameStack) {
|
||||
// Not empty but same type
|
||||
|
||||
// Amount of items that can be added before reaching capacity
|
||||
int reminder = maxCapacity - getCurrentCapacity();
|
||||
|
||||
|
||||
if (inputStack.getCount() <= reminder) {
|
||||
// Add full stack
|
||||
addStoredItemCount(inputStack.getCount());
|
||||
inputStack = ItemStack.EMPTY;
|
||||
} else {
|
||||
// Add only what is needed to reach max capacity
|
||||
addStoredItemCount(reminder);
|
||||
inputStack.decrement(reminder);
|
||||
}
|
||||
}
|
||||
|
||||
return inputStack;
|
||||
}
|
||||
|
||||
public boolean isSameType(ItemStack inputStack) {
|
||||
if (inputStack != ItemStack.EMPTY) {
|
||||
return ItemUtils.isItemEqual(getStoredStack(), inputStack, true, true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Creative function
|
||||
private void fillToCapacity() {
|
||||
storeItemStack = getStoredStack();
|
||||
storeItemStack.setCount(maxCapacity);
|
||||
|
||||
inventory.setInvStack(OUTPUT_SLOT, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
return getCurrentCapacity() == maxCapacity;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return getCurrentCapacity() == 0;
|
||||
}
|
||||
|
||||
public int getCurrentCapacity() {
|
||||
return storeItemStack.getCount() + inventory.getInvStack(OUTPUT_SLOT).getCount();
|
||||
}
|
||||
|
||||
public int getMaxCapacity() {
|
||||
return maxCapacity;
|
||||
}
|
||||
|
||||
// Other stuff
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(CompoundTag tagCompound) {
|
||||
super.fromTag(tagCompound);
|
||||
|
||||
if (tagCompound.contains("unitType")) {
|
||||
this.type = TRContent.StorageUnit.valueOf(tagCompound.getString("unitType"));
|
||||
configureEntity(type);
|
||||
} else {
|
||||
this.type = TRContent.StorageUnit.QUANTUM;
|
||||
}
|
||||
|
||||
storeItemStack = ItemStack.EMPTY;
|
||||
|
||||
if (tagCompound.contains("storedStack")) {
|
||||
storeItemStack = ItemStack.fromTag(tagCompound.getCompound("storedStack"));
|
||||
}
|
||||
|
||||
if (!storeItemStack.isEmpty()) {
|
||||
storeItemStack.setCount(Math.min(tagCompound.getInt("storedQuantity"), this.maxCapacity));
|
||||
}
|
||||
|
||||
inventory.read(tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tagCompound) {
|
||||
super.toTag(tagCompound);
|
||||
|
||||
tagCompound.putString("unitType", this.type.name());
|
||||
|
||||
if (!storeItemStack.isEmpty()) {
|
||||
ItemStack temp = storeItemStack.copy();
|
||||
if (storeItemStack.getCount() > storeItemStack.getMaxCount()) {
|
||||
temp.setCount(storeItemStack.getMaxCount());
|
||||
}
|
||||
tagCompound.put("storedStack", temp.toTag(new CompoundTag()));
|
||||
tagCompound.putInt("storedQuantity", Math.min(storeItemStack.getCount(), maxCapacity));
|
||||
} else {
|
||||
tagCompound.putInt("storedQuantity", 0);
|
||||
}
|
||||
inventory.write(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(this.getCurrentCapacity() + StringUtils.t("techreborn.tooltip.unit.divider") + this.getStoredStack().getName().asString()));
|
||||
} else {
|
||||
info.add(new TranslatableText("techreborn.tooltip.unit.empty"));
|
||||
}
|
||||
}
|
||||
|
||||
info.add(new LiteralText(Formatting.GRAY + StringUtils.t("techreborn.tooltip.unit.capacity") + ": " + Formatting.GOLD + this.getMaxCapacity() +
|
||||
" items (" + this.getMaxCapacity() / 64 + ")"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBreak(World world, PlayerEntity playerEntity, BlockPos blockPos, BlockState blockState) {
|
||||
super.onBreak(world, playerEntity, blockPos, blockState);
|
||||
|
||||
// No need to drop anything for creative peeps
|
||||
if (type == TRContent.StorageUnit.CREATIVE) {
|
||||
this.inventory.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (storeItemStack != ItemStack.EMPTY) {
|
||||
if (storeItemStack.getMaxCount() == 64) {
|
||||
// Drop stacks (In one clump, reduce lag)
|
||||
WorldUtils.dropItem(storeItemStack, world, pos);
|
||||
} else {
|
||||
int size = storeItemStack.getMaxCount();
|
||||
|
||||
for (int i = 0; i < storeItemStack.getCount() / size; i++) {
|
||||
ItemStack toDrop = storeItemStack.copy();
|
||||
toDrop.setCount(size);
|
||||
WorldUtils.dropItem(toDrop, world, pos);
|
||||
}
|
||||
|
||||
if (storeItemStack.getCount() % size != 0) {
|
||||
ItemStack toDrop = storeItemStack.copy();
|
||||
toDrop.setCount(storeItemStack.getCount() % size);
|
||||
WorldUtils.dropItem(toDrop, world, pos);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Inventory gets dropped automatically
|
||||
}
|
||||
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("chest").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).slot(0, 100, 53).outputSlot(1, 140, 53).addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue