Skip to content

Commit

Permalink
初步添加储罐
Browse files Browse the repository at this point in the history
  • Loading branch information
TartaricAcid committed Dec 23, 2023
1 parent b1445d2 commit 066a757
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.github.tartaricacid.touhoulittlemaid.client.gui.entity.maid.backpack;

import com.github.tartaricacid.touhoulittlemaid.TouhouLittleMaid;
import com.github.tartaricacid.touhoulittlemaid.client.gui.entity.maid.AbstractMaidContainerGui;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.github.tartaricacid.touhoulittlemaid.inventory.container.backpack.TankBackpackContainer;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;

public class TankBackpackContainerScreen extends AbstractMaidContainerGui<TankBackpackContainer> implements IBackpackContainerScreen {
private static final ResourceLocation BACKPACK = new ResourceLocation(TouhouLittleMaid.MOD_ID, "textures/gui/maid_gui_backpack.png");
private final EntityMaid maid;

public TankBackpackContainerScreen(TankBackpackContainer container, Inventory inv, Component titleIn) {
super(container, inv, titleIn);
this.imageHeight = 256;
this.imageWidth = 256;
this.maid = menu.getMaid();
}

@Override
protected void renderBg(GuiGraphics graphics, float partialTicks, int x, int y) {
super.renderBg(graphics, partialTicks, x, y);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, BACKPACK);
graphics.blit(BACKPACK, leftPos + 85, topPos + 36, 0, 0, 165, 128);
graphics.fill(leftPos + 142, topPos + 81, leftPos + 250, topPos + 117, 0xaa222222);
graphics.blit(BACKPACK, leftPos + 190, topPos + 92, 165, 0, 11, 11);
graphics.fill(leftPos + 142, topPos + 122, leftPos + 250, topPos + 158, 0xaa222222);
graphics.blit(BACKPACK, leftPos + 190, topPos + 133, 165, 0, 11, 11);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static void clientSetup(FMLClientSetupEvent evt) {
evt.enqueueWork(() -> MenuScreens.register(CraftingTableBackpackContainer.TYPE, CraftingTableBackpackContainerScreen::new));
evt.enqueueWork(() -> MenuScreens.register(EnderChestBackpackContainer.TYPE, EnderChestBackpackContainerScreen::new));
evt.enqueueWork(() -> MenuScreens.register(FurnaceBackpackContainer.TYPE, FurnaceBackpackContainerScreen::new));
evt.enqueueWork(() -> MenuScreens.register(TankBackpackContainer.TYPE, TankBackpackContainerScreen::new));

evt.enqueueWork(() -> MenuScreens.register(MaidConfigContainer.TYPE, MaidConfigContainerGui::new));
evt.enqueueWork(() -> MenuScreens.register(WirelessIOContainer.TYPE, WirelessIOContainerGui::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static void init() {
manager.add(new CraftingTableBackpack());
manager.add(new EnderChestBackpack());
manager.add(new FurnaceBackpack());
manager.add(new TankBackpack());
for (ILittleMaid littleMaid : TouhouLittleMaid.EXTENSIONS) {
littleMaid.addMaidBackpack(manager);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.github.tartaricacid.touhoulittlemaid.entity.backpack;

import com.github.tartaricacid.touhoulittlemaid.TouhouLittleMaid;
import com.github.tartaricacid.touhoulittlemaid.api.backpack.IBackpackData;
import com.github.tartaricacid.touhoulittlemaid.api.backpack.IMaidBackpack;
import com.github.tartaricacid.touhoulittlemaid.client.model.backpack.MiddleBackpackModel;
import com.github.tartaricacid.touhoulittlemaid.entity.backpack.data.TankBackpackData;
import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityTombstone;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.github.tartaricacid.touhoulittlemaid.inventory.container.AbstractMaidContainer;
import com.github.tartaricacid.touhoulittlemaid.inventory.container.backpack.TankBackpackContainer;
import com.github.tartaricacid.touhoulittlemaid.item.BackpackLevel;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.geom.EntityModelSet;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import javax.annotation.Nullable;

public class TankBackpack extends IMaidBackpack {
public static final ResourceLocation ID = new ResourceLocation(TouhouLittleMaid.MOD_ID, "tank");

@Override
public ResourceLocation getId() {
return ID;
}

@Override
public Item getItem() {
return Items.BUCKET;
}

@Override
public void onPutOn(ItemStack stack, Player player, EntityMaid maid) {
}

@Override
public void onTakeOff(ItemStack stack, Player player, EntityMaid maid) {
}

@Override
public void onSpawnTombstone(EntityMaid maid, EntityTombstone tombstone) {
}

@Nullable
@Override
public IBackpackData getBackpackData(EntityMaid maid) {
return new TankBackpackData();
}

@Override
public MenuProvider getGuiProvider(int entityId) {
return new MenuProvider() {
@Override
public Component getDisplayName() {
return Component.literal("Maid Tank Container");
}

@Override
public AbstractMaidContainer createMenu(int index, Inventory playerInventory, Player player) {
return new TankBackpackContainer(index, playerInventory, entityId);
}
};
}

@Override
public int getAvailableMaxContainerIndex() {
return BackpackLevel.TANK_CAPACITY;
}

@Nullable
@Override
@OnlyIn(Dist.CLIENT)
public EntityModel<EntityMaid> getBackpackModel(EntityModelSet modelSet) {
return new MiddleBackpackModel(modelSet.bakeLayer(MiddleBackpackModel.LAYER));
}

@Nullable
@Override
@OnlyIn(Dist.CLIENT)
public ResourceLocation getBackpackTexture() {
return new ResourceLocation(TouhouLittleMaid.MOD_ID, "textures/entity/maid_backpack_middle.png");
}

@OnlyIn(Dist.CLIENT)
public void offsetBackpackItem(PoseStack poseStack) {
poseStack.mulPose(Axis.XP.rotationDegrees(-7.5F));
poseStack.translate(0, 0.625, -0.25);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.github.tartaricacid.touhoulittlemaid.entity.backpack.data;

import com.github.tartaricacid.touhoulittlemaid.api.backpack.IBackpackData;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.inventory.ContainerData;
import net.minecraftforge.fluids.FluidType;
import net.minecraftforge.fluids.capability.templates.FluidTank;

public class TankBackpackData extends SimpleContainer implements IBackpackData {
public static final int CAPACITY = 10 * FluidType.BUCKET_VOLUME;
private final FluidTank tank = new FluidTank(CAPACITY);
private final ContainerData dataAccess = new ContainerData() {
public int get(int index) {
if (index == 0) {
TankBackpackData.this.tank.getFluidAmount();
}
return 0;
}

public void set(int index, int value) {
if (index == 0) {
TankBackpackData.this.tank.getFluid().setAmount(value);
}
}

public int getCount() {
return 2;
}
};

public TankBackpackData() {
super(2);
}

@Override
public ContainerData getDataAccess() {
return dataAccess;
}

@Override
public void load(CompoundTag tag, EntityMaid maid) {
tank.readFromNBT(tag.getCompound("Tanks"));
this.fromTag(tag.getList("Items", Tag.TAG_COMPOUND));
}

@Override
public void save(CompoundTag tag, EntityMaid maid) {
tag.put("Tanks", tank.writeToNBT(new CompoundTag()));
tag.put("Items", this.createTag());
}

@Override
public void serverTick(EntityMaid maid) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public final class InitContainer {
public static final RegistryObject<MenuType<CraftingTableBackpackContainer>> MAID_CRAFTING_TABLE_BACKPACK_CONTAINER = CONTAINER_TYPE.register("maid_crafting_table_backpack_container", () -> CraftingTableBackpackContainer.TYPE);
public static final RegistryObject<MenuType<EnderChestBackpackContainer>> MAID_ENDER_CHEST_CONTAINER = CONTAINER_TYPE.register("maid_ender_chest_container", () -> EnderChestBackpackContainer.TYPE);
public static final RegistryObject<MenuType<FurnaceBackpackContainer>> MAID_FURNACE_CONTAINER = CONTAINER_TYPE.register("maid_furnace_container", () -> FurnaceBackpackContainer.TYPE);
public static final RegistryObject<MenuType<TankBackpackContainer>> MAID_TANK_CONTAINER = CONTAINER_TYPE.register("maid_tank_container", () -> TankBackpackContainer.TYPE);

public static final RegistryObject<MenuType<MaidConfigContainer>> MAID_CONFIG_CONTAINER = CONTAINER_TYPE.register("maid_config_container", () -> MaidConfigContainer.TYPE);
public static final RegistryObject<MenuType<WirelessIOContainer>> WIRELESS_IO_CONTAINER = CONTAINER_TYPE.register("wireless_io_container", () -> WirelessIOContainer.TYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

public abstract class MaidMainContainer extends AbstractMaidContainer {
protected static final int PLAYER_INVENTORY_SIZE = 36;
private static final ResourceLocation EMPTY_BAUBLE_SLOT = new ResourceLocation(TouhouLittleMaid.MOD_ID, "slot/empty_bauble_slot");
private static final ResourceLocation EMPTY_MAINHAND_SLOT = new ResourceLocation("item/empty_slot_sword");
private static final ResourceLocation EMPTY_BACK_SHOW_SLOT = new ResourceLocation(TouhouLittleMaid.MOD_ID, "slot/empty_back_show_slot");
private static final ResourceLocation[] TEXTURE_EMPTY_SLOTS = new ResourceLocation[]{EMPTY_ARMOR_SLOT_BOOTS, EMPTY_ARMOR_SLOT_LEGGINGS, EMPTY_ARMOR_SLOT_CHESTPLATE, EMPTY_ARMOR_SLOT_HELMET};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.github.tartaricacid.touhoulittlemaid.inventory.container.backpack;

import com.github.tartaricacid.touhoulittlemaid.entity.backpack.data.TankBackpackData;
import com.github.tartaricacid.touhoulittlemaid.inventory.container.MaidMainContainer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.ContainerData;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.inventory.Slot;
import net.minecraftforge.common.extensions.IForgeMenuType;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;

public class TankBackpackContainer extends MaidMainContainer {
public static final MenuType<TankBackpackContainer> TYPE = IForgeMenuType.create((windowId, inv, data) -> new TankBackpackContainer(windowId, inv, data.readInt()));
private final ContainerData data;

public TankBackpackContainer(int id, Inventory inventory, int entityId) {
super(TYPE, id, inventory, entityId);
TankBackpackData tankData;
if (this.getMaid().getBackpackData() instanceof TankBackpackData) {
tankData = (TankBackpackData) this.getMaid().getBackpackData();
} else {
tankData = new TankBackpackData();
}
this.data = tankData.getDataAccess();
this.addSlot(new Slot(tankData, 0, 161, 101));
this.addSlot(new Slot(tankData, 1, 161, 142));
this.addDataSlots(this.data);
}

@Override
protected void addBackpackInv(Inventory inventory) {
IItemHandler itemHandler = maid.getMaidInv();
for (int i = 0; i < 6; i++) {
addSlot(new SlotItemHandler(itemHandler, 6 + i, 143 + 18 * i, 57));
}
for (int i = 0; i < 6; i++) {
addSlot(new SlotItemHandler(itemHandler, 12 + i, 143 + 18 * i, 75));
}
}

public int getTankPercent() {
return this.data.get(0) / TankBackpackData.CAPACITY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public final class BackpackLevel {
public static final int BIG_CAPACITY = 36;
public static final int CRAFTING_TABLE_CAPACITY = 18;
public static final int FURNACE_CAPACITY = 18;
public static final int TANK_CAPACITY = 18;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 066a757

Please sign in to comment.