diff --git a/src/main/java/com/atsuishio/superbwarfare/block/entity/ChargingStationBlockEntity.java b/src/main/java/com/atsuishio/superbwarfare/block/entity/ChargingStationBlockEntity.java new file mode 100644 index 000000000..6659d232d --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/block/entity/ChargingStationBlockEntity.java @@ -0,0 +1,172 @@ +package com.atsuishio.superbwarfare.block.entity; + +import com.atsuishio.superbwarfare.init.ModBlockEntities; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.core.NonNullList; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; +import net.minecraft.world.Container; +import net.minecraft.world.ContainerHelper; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.WorldlyContainer; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.items.wrapper.SidedInvWrapper; +import org.jetbrains.annotations.Nullable; + +public class ChargingStationBlockEntity extends BlockEntity implements WorldlyContainer, MenuProvider { + + protected static final int SLOT_FUEL = 0; + protected static final int SLOT_CHARGE = 1; + + private static final int[] SLOTS_FOR_UP = new int[]{0}; + private static final int[] SLOTS_FOR_SIDES = new int[]{0}; + private static final int[] SLOTS_FOR_DOWN = new int[]{0}; + + public static final int MAX_DATA_COUNT = 2; + public static final int FUEL_TIME = 200; + public static final int CHARGE_SPEED = 20; + + protected NonNullList items = NonNullList.withSize(2, ItemStack.EMPTY); + + private LazyOptional[] itemHandlers = SidedInvWrapper.create(this, Direction.UP, Direction.DOWN, Direction.NORTH); + + public int fuelTick; + public int energy; + + public ChargingStationBlockEntity(BlockPos pos, BlockState state) { + super(ModBlockEntities.CHARGING_STATION.get(), pos, state); + } + + public static void serverTick(Level pLevel, BlockPos pPos, BlockState pState, ChargingStationBlockEntity blockEntity) { + if (blockEntity.fuelTick > 0) { + + + + } + } + + public NonNullList getItems() { + return this.items; + } + + @Override + public void load(CompoundTag pTag) { + super.load(pTag); + + this.energy = pTag.getInt("Energy"); + this.fuelTick = pTag.getInt("FuelTick"); + this.items = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); + ContainerHelper.loadAllItems(pTag, this.items); + } + + @Override + protected void saveAdditional(CompoundTag pTag) { + super.saveAdditional(pTag); + + pTag.putInt("Energy", this.energy); + pTag.putInt("FuelTick", this.fuelTick); + ContainerHelper.saveAllItems(pTag, this.items); + } + + @Override + public int[] getSlotsForFace(Direction pSide) { + return new int[0]; + } + + @Override + public boolean canPlaceItemThroughFace(int pIndex, ItemStack pItemStack, @Nullable Direction pDirection) { + return pIndex == SLOT_FUEL; + } + + @Override + public boolean canTakeItemThroughFace(int pIndex, ItemStack pStack, Direction pDirection) { + return false; + } + + @Override + public int getContainerSize() { + return this.items.size(); + } + + @Override + public boolean isEmpty() { + for (ItemStack itemstack : this.items) { + if (!itemstack.isEmpty()) { + return false; + } + } + + return true; + } + + @Override + public ItemStack getItem(int pSlot) { + return this.items.get(pSlot); + } + + @Override + public ItemStack removeItem(int pSlot, int pAmount) { + return ContainerHelper.removeItem(this.items, pSlot, pAmount); + } + + @Override + public ItemStack removeItemNoUpdate(int pSlot) { + return ContainerHelper.takeItem(this.items, pSlot); + } + + @Override + public void setItem(int pSlot, ItemStack pStack) { + ItemStack itemstack = this.items.get(pSlot); + boolean flag = !pStack.isEmpty() && ItemStack.isSameItemSameTags(itemstack, pStack); + this.items.set(pSlot, pStack); + if (pStack.getCount() > this.getMaxStackSize()) { + pStack.setCount(this.getMaxStackSize()); + } + + if (pSlot == 0 && !flag) { + this.setChanged(); + } + } + + @Override + public boolean stillValid(Player pPlayer) { + return Container.stillValidBlockEntity(this, pPlayer); + } + + @Override + public void clearContent() { + this.items.clear(); + } + + @Override + public Component getDisplayName() { + return Component.translatable("container.superbwarfare.charging_station"); + } + + @Nullable + @Override + public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) { + return null; + } + + @Override + public ClientboundBlockEntityDataPacket getUpdatePacket() { + return ClientboundBlockEntityDataPacket.create(this); + } + + @Override + public CompoundTag getUpdateTag() { + CompoundTag compoundtag = new CompoundTag(); + ContainerHelper.saveAllItems(compoundtag, this.items, true); + return compoundtag; + } +} diff --git a/src/main/java/com/atsuishio/superbwarfare/energy/ItemEnergyProvider.java b/src/main/java/com/atsuishio/superbwarfare/capability/energy/ItemEnergyProvider.java similarity index 94% rename from src/main/java/com/atsuishio/superbwarfare/energy/ItemEnergyProvider.java rename to src/main/java/com/atsuishio/superbwarfare/capability/energy/ItemEnergyProvider.java index 5824a1ebb..2bef416be 100644 --- a/src/main/java/com/atsuishio/superbwarfare/energy/ItemEnergyProvider.java +++ b/src/main/java/com/atsuishio/superbwarfare/capability/energy/ItemEnergyProvider.java @@ -1,4 +1,4 @@ -package com.atsuishio.superbwarfare.energy; +package com.atsuishio.superbwarfare.capability.energy; import net.minecraft.core.Direction; import net.minecraft.world.item.ItemStack; @@ -12,6 +12,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; public class ItemEnergyProvider implements ICapabilityProvider { + private final LazyOptional capability; public ItemEnergyProvider(ItemStack stack, int energyCapacity) { diff --git a/src/main/java/com/atsuishio/superbwarfare/energy/ItemEnergyStorage.java b/src/main/java/com/atsuishio/superbwarfare/capability/energy/ItemEnergyStorage.java similarity index 95% rename from src/main/java/com/atsuishio/superbwarfare/energy/ItemEnergyStorage.java rename to src/main/java/com/atsuishio/superbwarfare/capability/energy/ItemEnergyStorage.java index 68ac0e1ee..bd800d1c6 100644 --- a/src/main/java/com/atsuishio/superbwarfare/energy/ItemEnergyStorage.java +++ b/src/main/java/com/atsuishio/superbwarfare/capability/energy/ItemEnergyStorage.java @@ -1,9 +1,10 @@ -package com.atsuishio.superbwarfare.energy; +package com.atsuishio.superbwarfare.capability.energy; import net.minecraft.world.item.ItemStack; import net.minecraftforge.energy.EnergyStorage; public class ItemEnergyStorage extends EnergyStorage { + private static final String NBT_ENERGY = "Energy"; private final ItemStack stack; diff --git a/src/main/java/com/atsuishio/superbwarfare/init/ModBlockEntities.java b/src/main/java/com/atsuishio/superbwarfare/init/ModBlockEntities.java index 11d684ba6..b6c678544 100644 --- a/src/main/java/com/atsuishio/superbwarfare/init/ModBlockEntities.java +++ b/src/main/java/com/atsuishio/superbwarfare/init/ModBlockEntities.java @@ -1,6 +1,7 @@ package com.atsuishio.superbwarfare.init; import com.atsuishio.superbwarfare.ModUtils; +import com.atsuishio.superbwarfare.block.entity.ChargingStationBlockEntity; import com.atsuishio.superbwarfare.block.entity.ContainerBlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraftforge.registries.DeferredRegister; @@ -13,5 +14,7 @@ public class ModBlockEntities { public static final RegistryObject> CONTAINER = REGISTRY.register("container", () -> BlockEntityType.Builder.of(ContainerBlockEntity::new, ModBlocks.CONTAINER.get()).build(null)); + public static final RegistryObject> CHARGING_STATION = REGISTRY.register("charging_station", + () -> BlockEntityType.Builder.of(ChargingStationBlockEntity::new, ModBlocks.CHARGING_STATION.get()).build(null)); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/SentinelItem.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/SentinelItem.java index e1b091311..f5962b986 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/SentinelItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/SentinelItem.java @@ -1,20 +1,20 @@ package com.atsuishio.superbwarfare.item.gun.sniper; import com.atsuishio.superbwarfare.ModUtils; +import com.atsuishio.superbwarfare.capability.energy.ItemEnergyProvider; +import com.atsuishio.superbwarfare.client.PoseTool; import com.atsuishio.superbwarfare.client.renderer.item.SentinelItemRenderer; -import com.atsuishio.superbwarfare.energy.ItemEnergyProvider; +import com.atsuishio.superbwarfare.client.tooltip.component.SentinelImageComponent; import com.atsuishio.superbwarfare.event.ClientEventHandler; +import com.atsuishio.superbwarfare.init.ModItems; +import com.atsuishio.superbwarfare.init.ModSounds; +import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.AnimatedItem; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.RarityTool; -import com.atsuishio.superbwarfare.client.PoseTool; -import com.atsuishio.superbwarfare.client.tooltip.component.SentinelImageComponent; -import com.atsuishio.superbwarfare.init.ModItems; -import com.atsuishio.superbwarfare.init.ModSounds; -import com.atsuishio.superbwarfare.init.ModTags; -import com.atsuishio.superbwarfare.item.AnimatedItem; import net.minecraft.client.Minecraft; import net.minecraft.client.model.HumanoidModel; import net.minecraft.client.player.LocalPlayer; diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/special/TaserItem.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/special/TaserItem.java index 7375b2de7..ddfb52bc6 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/special/TaserItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/special/TaserItem.java @@ -1,10 +1,10 @@ package com.atsuishio.superbwarfare.item.gun.special; import com.atsuishio.superbwarfare.ModUtils; +import com.atsuishio.superbwarfare.capability.energy.ItemEnergyProvider; import com.atsuishio.superbwarfare.client.PoseTool; import com.atsuishio.superbwarfare.client.renderer.item.TaserItemRenderer; import com.atsuishio.superbwarfare.client.tooltip.component.EnergyImageComponent; -import com.atsuishio.superbwarfare.energy.ItemEnergyProvider; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModPerks;