Jump to content
Search In
  • More options...
Find results that contain...
Find results in...


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by GnRSlashSP

  1. Oh, Now I understand. public class TextureStitchEvent extends Event implements IModBusEvent -> this means it is MOD bus Thank you!
  2. Hi! I want to understand how this works. Reading Forge Documentation I made this at first: @Mod.EventBusSubscriber(modid = RedOptionsMod.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class StaticClientOnlyEventHandler { @SubscribeEvent public static void spriteAdd(TextureStitchEvent.Pre event) { if (!event.getMap().location().equals(InventoryMenu.BLOCK_ATLAS)) return; event.addSprite(Resources.FILTER); } } But this event is never fired (I don't think it should have been registered..)So, I removed the line: @Mod.EventBusSubscriber, and I did this at my mod class: if (FMLLoader.getDist().isClient()) FMLJavaModLoadingContext.get().getModEventBus().register(StaticClientOnlyEventHandler.class); And it is working (working and don't crashing at server side). Tow questions: 1. Why the first method didn't work, am I missing something? 2. Is the second way the correct way to register specific side events, using (FMLLoader.getDist().isClient()) ? Thank you!
  3. I saw this but I didn't realize that I could just create a minecraft folder inside my assets lol I was so simple, thanks!!
  4. Hi, I already create a new arrow type and it is working. StoneArrow. Everything is working including minecraft Bow and CrossBow are using my custom arrow BUT I am doing the register manually using breakpoints inside BowItem.java I am using these two lines to make my arrow be accepted by normal bow: ItemTags.getCollection().get(new ResourceLocation("arrows")).getEntries().add(new Tag.TagEntry<Item>(ModItems.ITEM_STONE_ARROW.getRegistryName())); ItemTags.getCollection().get(new ResourceLocation("arrows")).getAllElements().add(ModItems.ITEM_STONE_ARROW); I would like to know these two things: 1. Where is the right place (and time), that I can add my arrow to ItemTags 2. Is it right the code above? It seams not right for me because I used two lines... stranged thing Thank you!
  5. I think I solved this issue... GnRSharedLib has a pack.metadata and inside it has a description key. Instead of write gnrsharedlib I wrote GnRSharedLib (using caps....)
  6. Diesieben, thanks for the explanation. It's really complicated, but now I have a chance to write code the right way. So I changed the code from: PlayerEntity playerEntity = Minecraft.getInstance().player to: ClientPlayerEntity playerEntity = Minecraft.getInstance().player; and it works! But I still don't know why this do not work (even if I put all inside DistExecutor): if (ctx.get().getDirection().getReceptionSide().isClient()) { Minecraft.getInstance().displayGuiScreen(new XPTransferScreen(playerIDToTransfer, playerName)); } and this works: if (ctx.get().getDirection().getReceptionSide().isClient()) { XPTransferScreen.open(playerID, playerName); } this is inside XPTransfer class, that extends Screen: public static void open(int playerIDToTransfer, String playerName) { Minecraft.getInstance().displayGuiScreen(new XPTransferScreen(playerIDToTransfer, playerName)); } I just want to open a simple Screen, without container, just buttons, textfields
  7. Change the name of the lang file to en_US.json
  8. I am a little confused when I need to use the same message on both sides. When I want to execute client side code like Minecraft.getInstance(), I can use this: DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { // this is client side PlayerEntity playerEntity = Minecraft.getInstance().player; Entity entity = playerEntity.world.getEntityByID(entityId); .... // the rest of code here }); but this is generating an error when I try to start the server.... the error occurs while registering network messages because there is Minecraft.getInstance in message body... I don't know when to use this: Dist.DEDICATED_SERVER because I'm afraid of the code inside it only runs if the server is physical, I mean, the code inside this will not run when minecraft is running in single player mode. Another approach that I used (but again I am not sure what I am doing), was this: if (ctx.get().getDirection().getReceptionSide().isServer()) { ent = ctx.get().getSender().world.getEntityByID(playerID); if (ent instanceof PlayerEntity) { // server side code here.... } } else if (ctx.get().getDirection().getReceptionSide().isClient()) { XPTransferScreen.open(playerID, playerName); } Note that I am not using Client methods here directly, but I put the client part inside the XPTransferScreen.open method: public static void open(int playerIDToTransfer, String playerName) { Minecraft.getInstance().displayGuiScreen(new XPTransferScreen(playerIDToTransfer, playerName)); } This way the code runs without problems on single player and dedicated server. So my question is: Which method should i use? (DistExecutor or getReceptionSide) ? If your answer is DistExecutor, I have another question: How can I run it server side and single player, Dist.DEDICATED_SERVER will run like server side if I run the single player game? Thanks! †GnR† Slash
  9. I think this is the problem. According to documentation, you need to write it this way: ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, ServerConfig.CONFIG); ServerConfig.loadConfig(ServerConfig.CONFIG, FMLPaths.CONFIGDIR.get().resolve(modid +"-server.toml")); You don't need to specify the file name, it will be your MODID name. Keep it simple and you will stay out of trouble and this: ServerConfig.loadConfig(ServerConfig.CONFIG, FMLPaths.CONFIGDIR.get().resolve("modid-server.toml").toString()); will not compile, the last parameter needs to be Path not String
  10. It is working! Of course, using this event solved my issue with drawing color but cause me issues with coordinates. Before using GuiContainerEvent: double mouseX = mc.mouseHelper.getMouseX() * (double)mc.mainWindow.getScaledWidth() / (double)mc.mainWindow.getWidth(); double mouseY = mc.mouseHelper.getMouseY() * (double)mc.mainWindow.getScaledHeight() / (double)mc.mainWindow.getHeight(); mc.fontRenderer.drawString(Resources.getMsg("item"), searchBar.x - 3 - mc.fontRenderer.getStringWidth(Resources.getMsg("item")), searchBar.y, 0x606060); mc.fontRenderer.drawString(Resources.getMsg("qty"), qtyBar.x - 3 - mc.fontRenderer.getStringWidth(Resources.getMsg("qty")), qtyBar.y, 0x606060); After using GuiContainerEvent: double mouseX = mc.mouseHelper.getMouseX() * (double)mc.mainWindow.getScaledWidth() / (double)mc.mainWindow.getWidth(); double mouseY = mc.mouseHelper.getMouseY() * (double)mc.mainWindow.getScaledHeight() / (double)mc.mainWindow.getHeight(); double newY = -(mc.mainWindow.getScaledHeight() - ((ContainerScreen) mc.currentScreen).getYSize())/2; double newX = -(mc.mainWindow.getScaledWidth() - ((ContainerScreen) mc.currentScreen).getXSize())/2; GlStateManager.translated(newX, newY, 1d); mc.fontRenderer.drawString(Resources.getMsg("item"), searchBar.x - 3 - mc.fontRenderer.getStringWidth(Resources.getMsg("item")), searchBar.y, 0x606060); mc.fontRenderer.drawString(Resources.getMsg("qty"), qtyBar.x - 3 - mc.fontRenderer.getStringWidth(Resources.getMsg("qty")), qtyBar.y, 0x606060); Another thing, after all code inside this event, I need to use this again: GlStateManager.translated(-newX, -newY, 1d); Without this, when I click a slot to drag itemstack, the item appear at wrong locations at screen lol Thank you!
  11. Hey, Lets make simple things to test complex things: Create a single player world, customized to be superflat (this way, nothing will hinder you) Enter creative mode, put your specific block anywhere (write down the block positions) Put a breakpoint somewhere in the code to stop when the mod gets the goal to that block Spawn your mob a few blocks near these block At the breakpoint, watch the variable that have the final destination position, this must be the same coords of the block! (see if rounding problems is occuring here). Good luck.
  12. I don't know what you are saying with "Spawn ItemStack", because ItemStacks can't "Spawn". If you have a ItemStack and want this item to Spawn in world right above players head, use ItemEntity (search how mobs drops its inventory and copy the code there). But if you want to put a specific ItemStack in player armor head position inventory, its simple: playerEntity.armorinventory.set(slot, itemstack) // don't remember if player head slot is 0 or 3, try it Always do these things SERVER side.
  13. Hi, I am trying to draw a gui with buttons over another screen always when player open a Screen that is instance of Container. It is working very well except the background texture. I tryed to use Forge's events like: RenderGameOverlayEvent.Post / Pre GuiScreenEvent.DrawScreenEvent.Post / Pre GuiScreenEvent.DrawScreenEvent.BackgroundDrawnEvent When I open my own custom gui, it works (the little gui at the top of screen is the GUI that I am talking about, drawned by forge events described above): https://paste.pics/e0840bd62f40d65c805edc31474ec2c8 But, if I open player inventory or crafting table or chest containers, this is what happens to my overlay gui (grayed out) https://paste.pics/65c5c355f7597296d13def7459c715c0 I tried to enable/disable GL11 lighting, blend, etc... but I am not good with grapichs parts... This is my current "working" code: @SubscribeEvent public static void onScreenRender(RenderGameOverlayEvent.Post event) { if (event.getType() == RenderGameOverlayEvent.ElementType.EXPERIENCE) { if (mc.currentScreen instanceof ContainerScreen<?> && !(mc.currentScreen instanceof CreativeScreen)) { GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); RenderHelper.disableStandardItemLighting(); mc.getTextureManager().bindTexture(SEARCH_GUI); // SEARCH_GUI is a ResourceLocation mc.currentScreen.blit(guiLeft, guiTop, 0, 0, xSize, ySize); } } } Can anyone help me about this? Thank you!
  14. I was looking at ItemStackHandler and the difference mine is too slight, ItemHandler is missing some features like listeners, clear inventory, isEmpty, MarkDirt. So, this is reasonable if it syncs with client for me automatically. I changed from "extends Inventory" to extends "ItemHandler" and now I cant add slots because new slot needs Inventory class. Let me see ... Did I get it right? If I implement correctly, will the inventory automatically sync without having to create custom network messages or ItemHandler is just a way to writeToNBT automatically? thanks
  15. Hi, You need to override keyPressed too and put logic inside to pass the key information to textwidget if it has focus Something like this: @Override public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) { if (txtXPToTransfer.isFocused()) { txtXPToTransfer.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_); } return super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_); }
  16. Last question: Do you know if there is a repository that contains "entity with inventory" that I can use as a study? I confess that from forge 1.7.10 to 1.15 is very difficult for me, I can learn fast from examples. Thank you
  17. Sorry, I posted hede because I am trying to use exact the same code. Next time I'll create new topic Ok, all code is now there. Sorry I know, but I don't know what I have to do inside it yet
  18. Hi I am doing the same thing here (custom entity inventory) and I got lost when you said this. I didn't find any mention about (SiegeContainerFactory and SiegeScreenFactory) inside classes at first post My code is working except that client does not have itemstacks syncronized (it is empty). By the way, these are important parts of my mod Can anybody help me please? Thank you †GnR† Slash DeadPlayerContainer: package com.gnrdevand.inventoryplus.inventory; import com.gnrdevand.inventoryplus.entities.DeadPlayerEntity; import com.gnrdevand.inventoryplus.init.ContainerTypes; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.Slot; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketBuffer; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import javax.annotation.Nullable; import java.awt.*; public class DeadPlayerContainer extends Container { private static final String[] ARMOR_SLOT_TEXTURES = new String[]{"item/empty_armor_slot_boots", "item/empty_armor_slot_leggings", "item/empty_armor_slot_chestplate", "item/empty_armor_slot_helmet"}; private static final EquipmentSlotType[] VALID_EQUIPMENT_SLOTS = new EquipmentSlotType[]{EquipmentSlotType.HEAD, EquipmentSlotType.CHEST, EquipmentSlotType.LEGS, EquipmentSlotType.FEET}; private final Point firstArmorSlot = new Point(8, 8); private final Point firstInvSlot = new Point(44, 9); private final Point firstPlayerArmorSlot = new Point(8, 98); private final Point firstPlayerInvSlot = new Point(44, 98); private final PlayerInventory playerInventory; private final DeadPlayerEntity deadPlayerEntity; private int ctSlotIndex; private int firstArmorSlotIndex; private int firstOffHandSlotIndex; private int firstMainSlotIndex; private int firstMainHandSlotIndex; private int firstPlayerArmorSlotIndex; private int firstPlayerOffHandPSlotIndex; private int firstPlayerMainPSlotIndex; private int firstPlayerMainHandSlotIndex; public DeadPlayerContainer(int containerId, PlayerInventory playerInv, PacketBuffer buffer) { this(containerId, playerInv, (DeadPlayerEntity) playerInv.player.world.getEntityByID(buffer.readInt())); } public DeadPlayerContainer(int containerIdIn, PlayerInventory playerInventoryIn, DeadPlayerEntity deadPlayerEntityIn) { super(ContainerTypes.DEAD_PLAYER_CONTAINER.get(), containerIdIn); this.deadPlayerEntity = deadPlayerEntityIn; this.playerInventory = playerInventoryIn; this.deadPlayerEntity.getMainInventory().openInventory(playerInventoryIn.player); this.deadPlayerEntity.getArmorInventory().openInventory(playerInventoryIn.player); this.deadPlayerEntity.getOffHandInventory().openInventory(playerInventoryIn.player); addContainerSlots(); addPlayerSlots(); } @Override public boolean canInteractWith(PlayerEntity playerIn) { return playerIn.getDistanceSq(deadPlayerEntity.posX, deadPlayerEntity.posY, deadPlayerEntity.posZ) <= 64D; } @Override public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) { return super.transferStackInSlot(playerIn, index); } @Override public void onContainerClosed(PlayerEntity playerIn) { super.onContainerClosed(playerIn); this.deadPlayerEntity.getInventory().getInventories().forEach((s, invEnt) -> { invEnt.closeInventory(playerIn); }); } private void addContainerSlots() { ctSlotIndex = 0; // armor slots firstArmorSlotIndex = ctSlotIndex; for (int i = 0; i < 4; i++) { final EquipmentSlotType equipmentslottype = VALID_EQUIPMENT_SLOTS[i]; addSlot(new Slot( deadPlayerEntity.getArmorInventory(), ctSlotIndex, firstArmorSlot.x, firstArmorSlot.y + 18 * i){ @Override public int getSlotStackLimit() { return 1; } @Override public boolean isItemValid(ItemStack stack) { return stack.canEquip(equipmentslottype, playerInventory.player); } @Nullable @OnlyIn(Dist.CLIENT) @Override public String getSlotTexture() { return DeadPlayerContainer.ARMOR_SLOT_TEXTURES[equipmentslottype.getIndex()]; } }); ctSlotIndex++; } // off hand slot firstOffHandSlotIndex = ctSlotIndex; this.addSlot(new Slot(deadPlayerEntity.getOffHandInventory(), ctSlotIndex, firstArmorSlot.x + 18, firstArmorSlot.y + 18 * 3) { @Nullable @OnlyIn(Dist.CLIENT) public String getSlotTexture() { return "item/empty_armor_slot_shield"; } }); ctSlotIndex++; // main slots firstMainSlotIndex = ctSlotIndex; for (int row = 0; row < 3; row++) { for (int col = 0; col < 9; col++) { addSlot(new Slot(deadPlayerEntity.getMainInventory(), ctSlotIndex, firstInvSlot.x + col * 18, firstInvSlot.y + row * 18)); ctSlotIndex++; } } // main hand slots firstMainHandSlotIndex = ctSlotIndex; for (int i = 0; i < 9; i++) { addSlot(new Slot(deadPlayerEntity.getMainInventory(), ctSlotIndex, firstInvSlot.x + i * 18, firstInvSlot.y + 18 * 3)); ctSlotIndex++; } } private void addPlayerSlots() { // armor slots firstPlayerArmorSlotIndex = ctSlotIndex; for (int i = 0; i < 4; i++) { final EquipmentSlotType equipmentslottype = VALID_EQUIPMENT_SLOTS[i]; addSlot(new Slot( playerInventory, playerInventory.getSizeInventory() - 5 + 1, firstPlayerArmorSlot.x, firstPlayerArmorSlot.y + 18 * i){ @Override public int getSlotStackLimit() { return 1; } @Override public boolean isItemValid(ItemStack stack) { return stack.canEquip(equipmentslottype, playerInventory.player); } @Nullable @OnlyIn(Dist.CLIENT) @Override public String getSlotTexture() { return DeadPlayerContainer.ARMOR_SLOT_TEXTURES[equipmentslottype.getIndex()]; } }); ctSlotIndex++; } // off hand slot firstPlayerOffHandPSlotIndex = ctSlotIndex; this.addSlot(new Slot(playerInventory, playerInventory.getSizeInventory() - 1, firstPlayerArmorSlot.x + 18, firstPlayerArmorSlot.y + 18 * 3) { @Nullable @OnlyIn(Dist.CLIENT) public String getSlotTexture() { return "item/empty_armor_slot_shield"; } }); ctSlotIndex++; // main slots firstPlayerMainPSlotIndex = ctSlotIndex; for (int row = 0; row < 3; row++) { for (int col = 0; col < 9; col++) { addSlot(new Slot(playerInventory, col + (row + 1) * 9, firstPlayerInvSlot.x + col * 18, firstPlayerInvSlot.y + row * 18)); ctSlotIndex++; } } // main hand slots firstPlayerMainHandSlotIndex = ctSlotIndex; for (int i = 0; i < 9; i++) { addSlot(new Slot(playerInventory, i, firstPlayerInvSlot.x + i * 18, firstPlayerInvSlot.y + 18 * 3)); } } public DeadPlayerEntity getDeadPlayerEntity() { return this.deadPlayerEntity; } } ContainerTypes: package com.gnrdevand.inventoryplus.init; import com.gnrdevand.inventoryplus.InventoryPlus; import com.gnrdevand.inventoryplus.inventory.DeadPlayerContainer; import net.minecraft.inventory.container.ContainerType; import net.minecraftforge.common.extensions.IForgeContainerType; import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; public class ContainerTypes { public static final DeferredRegister<ContainerType<?>> CONTAINER_TYPES = new DeferredRegister<>(ForgeRegistries.CONTAINERS, InventoryPlus.MODID); public static final RegistryObject<ContainerType<DeadPlayerContainer>> DEAD_PLAYER_CONTAINER = CONTAINER_TYPES.register(InventoryPlus.MODID, () -> { return IForgeContainerType.create(DeadPlayerContainer::new); }); } MainMod: package com.gnrdevand.inventoryplus; import com.gnrdevand.inventoryplus.gui.DeadPlayerInventoryScreen; import com.gnrdevand.inventoryplus.init.ConfigHandler; import com.gnrdevand.inventoryplus.init.ContainerTypes; import com.gnrdevand.inventoryplus.network.Networking; import net.minecraft.client.gui.ScreenManager; import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.util.InputMappings; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.config.ModConfig; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.loading.FMLPaths; import java.util.logging.Logger; @Mod(InventoryPlus.MODID) public final class InventoryPlus { public static final String MODID = "inventoryplus"; public static final Logger LOGGER = Logger.getLogger(MODID); public InventoryPlus() { ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ConfigHandler.CLIENT_CONFIG); ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ConfigHandler.COMMON_CONFIG); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientRegistries); ConfigHandler.loadConfig(ConfigHandler.CLIENT_CONFIG, FMLPaths.CONFIGDIR.get().resolve(MODID + "-client.toml")); ConfigHandler.loadConfig(ConfigHandler.COMMON_CONFIG, FMLPaths.CONFIGDIR.get().resolve(MODID + "-common.toml")); ContainerTypes.CONTAINER_TYPES.register(FMLJavaModLoadingContext.get().getModEventBus()); } private void setup(final FMLCommonSetupEvent event) { Networking.registerMessages(); } private void clientRegistries(FMLClientSetupEvent event) { ScreenManager.registerFactory(ContainerTypes.DEAD_PLAYER_CONTAINER.get(), DeadPlayerInventoryScreen::new); } } I did not understand this part of MainMod class: (ContainerTypes.CONTAINER_TYPES.register(FMLJavaModLoadingContext.get().getModEventBus());) DeadPlayerInventoryScreen: package com.gnrdevand.inventoryplus.gui; import com.gnrdevand.gnrsharedlib.gui.controls.ButtonExt; import com.gnrdevand.inventoryplus.entities.DeadPlayerEntity; import com.gnrdevand.inventoryplus.inventory.DeadPlayerContainer; import com.gnrdevand.inventoryplus.lib.Resources; import com.mojang.blaze3d.platform.GlStateManager; import net.minecraft.client.gui.screen.inventory.ContainerScreen; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) public class DeadPlayerInventoryScreen extends ContainerScreen<DeadPlayerContainer> { private final PlayerInventory playerInventory; private final DeadPlayerEntity deadPlayerEntity; private float mousePosx; private float mousePosY; public DeadPlayerInventoryScreen(DeadPlayerContainer container, PlayerInventory playerInventoryIn, ITextComponent tileIn) { super(container, playerInventoryIn, tileIn); this.playerInventory = playerInventoryIn; this.deadPlayerEntity = container.getDeadPlayerEntity(); } @Override protected void init() { xSize = 211; ySize = 179; super.init(); String txt = Resources.getMsg("transfer"); addButton(new ButtonExt(this, guiLeft + xSize - 20 - font.getStringWidth(txt) - 6, guiTop + (18 * 4) + 6, font.getStringWidth(txt) + 20, 20, txt, btnClick -> { })); } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); this.minecraft.getTextureManager().bindTexture(Resources.DEAD_PLAYER_GUI); int x = (this.width - this.xSize) / 2; int y = (this.height - this.ySize) / 2; this.blit(x, y, 0, 0, this.xSize, this.ySize); } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { this.font.drawString(this.playerInventory.getDisplayName().getFormattedText(), 7, (18 * 4) + 6 + font.FONT_HEIGHT, 4210752); } @Override public void render(int mouseX, int mouseY, float partialTicks) { this.mousePosx = mouseX; this.mousePosY = mouseY; super.render(mouseX, mouseY, partialTicks); this.renderHoveredToolTip(mouseX, mouseY); } } DeadPlayerEntity: package com.gnrdevand.inventoryplus.entities; import com.gnrdevand.inventoryplus.init.ConfigHandler; import com.gnrdevand.inventoryplus.init.ModEntities; import com.gnrdevand.inventoryplus.inventory.DeadPlayerContainer; import net.minecraft.entity.CreatureEntity; import net.minecraft.entity.EntitySize; import net.minecraft.entity.EntityType; import net.minecraft.entity.Pose; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.PacketBuffer; import net.minecraft.network.datasync.DataParameter; import net.minecraft.network.datasync.DataSerializers; import net.minecraft.network.datasync.EntityDataManager; import net.minecraft.util.DamageSource; import net.minecraft.util.Hand; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.World; import net.minecraftforge.fml.network.NetworkHooks; import javax.annotation.Nullable; import java.util.function.Consumer; public class DeadPlayerEntity extends CreatureEntity { public static final String name = "dead_player_entity"; private static final DataParameter<Integer> DATA_BORN_TIME = EntityDataManager.createKey(DeadPlayerEntity.class, DataSerializers.VARINT); private static final DataParameter<String> DATA_CUSTOM_NAME = EntityDataManager.createKey(DeadPlayerEntity.class, DataSerializers.STRING); private final DeadPlayerEntityInventoryContainerProvider containerProvider; private int timeToDie; private String customName; private InventoryForEntities inventory; public enum eDeadPlayerInvTypes { ARMOR("armorInventory"), MAIN("mainInventory"), OFFHAND("offHandInventory"); private String type; eDeadPlayerInvTypes(String type) { this.type = type; } public String getType() { return this.type; } } public DeadPlayerEntity(EntityType<? extends CreatureEntity> type, World worldIn) { super((EntityType<? extends CreatureEntity>) ModEntities.DEAD_PLAYER_ENTITY, worldIn); this.timeToDie = 20 * 60 * ConfigHandler.CFG_DEAD_BODY_TIME.get(); // in minutes this.setInvulnerable(true); inventory = new InventoryForEntities(this); inventory.addInventory(eDeadPlayerInvTypes.MAIN.getType(), 9 * 4); // Player Inventory + Player quick inventory inventory.addInventory(eDeadPlayerInvTypes.ARMOR.getType(), 4); // Player Armor inventory.addInventory(eDeadPlayerInvTypes.OFFHAND.getType(), 1); // Player off hand item inventory.setMustDieOnPeacefull(false); inventory.setCanDropInventoryOnDeath(true); this.containerProvider = new DeadPlayerEntityInventoryContainerProvider(this); } public InventoryForEntities getInventory() { return this.inventory; } public InventoryEntity getArmorInventory() { return this.inventory.getInventory(eDeadPlayerInvTypes.ARMOR.getType()); } public InventoryEntity getOffHandInventory() { return this.inventory.getInventory(eDeadPlayerInvTypes.OFFHAND.getType()); } public InventoryEntity getMainInventory() { return this.inventory.getInventory(eDeadPlayerInvTypes.MAIN.getType()); } public long getTimeToDie() { return this.timeToDie; } public void setName(String name) { customName = name; this.dataManager.set(DATA_CUSTOM_NAME, customName); } public boolean copyPlayerInventory(PlayerEntity player) { boolean hasInv = false; for (int i = 0; i < player.inventory.armorInventory.size(); i++) { inventory.getInventory(eDeadPlayerInvTypes.ARMOR.getType()).addItem(player.inventory.armorInventory.get(i).copy()); if (!player.inventory.armorInventory.get(i).isEmpty()) hasInv = true; } inventory.getInventory(eDeadPlayerInvTypes.OFFHAND.getType()).addItem(player.inventory.offHandInventory.get(0).copy()); if (!player.inventory.offHandInventory.get(0).isEmpty()) hasInv = true; for (int i = 0; i < player.inventory.mainInventory.size(); i++) { inventory.getInventory(eDeadPlayerInvTypes.MAIN.getType()).addItem(player.inventory.mainInventory.get(i).copy()); if (!player.inventory.mainInventory.get(i).isEmpty()) hasInv = true; } return hasInv; } @Override protected void registerData() { super.registerData(); this.getDataManager().register(DATA_BORN_TIME, 0); this.getDataManager().register(DATA_CUSTOM_NAME, ""); } @Override public void writeAdditional(CompoundNBT compound) { super.writeAdditional(compound); compound.putInt("DATA_BORN_TIME", timeToDie); compound.putString("DATA_CUSTOM_NAME", customName); inventory.getInventories().forEach((name, invEnt) -> { compound.put(name, invEnt.writeToNBT()); }); } @Override public void readAdditional(CompoundNBT compound) { super.readAdditional(compound); timeToDie = compound.getInt("DATA_BORN_TIME"); customName = compound.getString("DATA_CUSTOM_NAME"); inventory.getInventories().forEach((name, invEnt) -> { invEnt.readFromNBT(compound.getList(name, 10)); }); } @Override public EntitySize getSize(Pose poseIn) { return EntitySize.fixed(1.8F, 0.2F); } @Override protected boolean isMovementBlocked() { return true; } @Override public boolean canBeSteered() { return false; } @Override public boolean canDespawn(double distanceToClosestPlayer) { return false; } @Override public void livingTick() { if (!ConfigHandler.CFG_USE_DEAD_BODY.get() && !world.isRemote) { this.setHealth(0); this.remove(); return; } super.livingTick(); //if (bornTime > 0) bornTime--; if (timeToDie <=0) { this.setHealth(0); this.onDeath(DamageSource.OUT_OF_WORLD); this.remove(); } else if (!world.isRemote) { int seconds = timeToDie / 20; this.setCustomName(new StringTextComponent(customName + " > " + String.format("%02d", (int) (seconds / 60)) + ":" + String.format("%02d", (int) (seconds % 60)))); } } @Override protected boolean processInteract(PlayerEntity player, Hand hand) { if (hand == Hand.MAIN_HAND && !player.world.isRemote && player instanceof ServerPlayerEntity) { NetworkHooks.openGui((ServerPlayerEntity) player, this.containerProvider, new Consumer<PacketBuffer>() { @Override public void accept(PacketBuffer buffer) { buffer.writeInt(getEntityId()); } }); return true; } return super.processInteract(player, hand); } @Override public void onDeath(DamageSource cause) { super.onDeath(cause); if (!world.isRemote) { inventory.getInventory(eDeadPlayerInvTypes.ARMOR.getType()).dropInventoryItems(); inventory.getInventory(eDeadPlayerInvTypes.OFFHAND.getType()).dropInventoryItems(); inventory.getInventory(eDeadPlayerInvTypes.MAIN.getType()).dropInventoryItems(); } } @Override public ItemStack getItemStackFromSlot(EquipmentSlotType slotIn) { if (slotIn == EquipmentSlotType.MAINHAND) { return this.inventory.getInventory(eDeadPlayerInvTypes.MAIN.getType()).getStackInSlot(0); } else if (slotIn == EquipmentSlotType.OFFHAND) { return this.inventory.getInventory(eDeadPlayerInvTypes.OFFHAND.getType()).getStackInSlot(0); } else { return slotIn.getSlotType() == EquipmentSlotType.Group.ARMOR ? this.inventory.getInventory(eDeadPlayerInvTypes.ARMOR.getType()).getStackInSlot(slotIn.getIndex()) : ItemStack.EMPTY; } } } class DeadPlayerEntityInventoryContainerProvider implements INamedContainerProvider { private final DeadPlayerEntity deadPlayerEntity; public DeadPlayerEntityInventoryContainerProvider(DeadPlayerEntity deadPlayerEntity) { this.deadPlayerEntity = deadPlayerEntity; } @Nullable @Override public Container createMenu(int containerId, PlayerInventory playerInv, PlayerEntity player) { return new DeadPlayerContainer(containerId, playerInv, this.deadPlayerEntity); } @Override public ITextComponent getDisplayName() { return deadPlayerEntity.getDisplayName(); } }
  19. Hi, I am the developer of these mods: Amazing Minecraft Mods, (for 1.7.10), and now I am writing mods for 1.14.4. Everything is going very well except one thing: I want to work with Intellij and use one of my mods as library methods for another mod. What I have: 1. Two mods called InventoryPlus and HostileLands (these are the main mods) 2. Another mod called GnRSharedLib (this is a mod but it does nothing, I just have all shared methods inside it) I want to use GnRSharedLib mod as library for InventoryPlus and HostileLands, so I compiled the gnrsharedlib into a deob jar and changed build.gradle of inventoryPlus and HostileLands this way: dependencies { minecraft 'net.minecraftforge:forge:1.14.4-28.2.10' compile files('../GnrSharedLib/build/libs/gnrsharedlib-1.14.4-') } compileJava { exclude '../GnrSharedLib/build/libs/gnrsharedlib-1.14.4-' } I can test the mod in dev environment and it works, but when I click in Minecraft MODS button and click the GnRSharedLib mod in the list, the game crashs The same thing happens in Minecraft final release with my mods inside mods folder This is the log: Crash Log If someone have an idea on how can I do this, I'll appreciate. Thank you for your patience and sorry for english mistakes, I 'm from Brazil. †GnR† Slash
  20. Please, how did you configure it? https://www.jetbrains.com/help/idea/gradle-settings.html <--- this does not solve the problem, it says that there are not do change I have the same problem but I am working with only one project....
  21. Ok, I got it working!!! This is what I did: I put a file named entitytest.png inside textures/entities/ of my jar User will put a new texture in this folder .minecraft\ When he clicks the button, I execute this piece of magic code: String textureName = "entitytest.png"; File textureFile = null; try { textureFile = new File(Minecraft.getMinecraft().mcDataDir.getCanonicalPath(), textureName); } catch (Exception ex) {} if (textureFile != null && textureFile.exists()) { ResourceLocation MODEL_TEXTURE = Resources.OTHER_TESTMODEL_CUSTOM; TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); texturemanager.deleteTexture(MODEL_TEXTURE); Object object = new ThreadDownloadImageData(textureFile, null, MODEL_TEXTURE, new ImageBufferDownload()); texturemanager.loadTexture(MODEL_TEXTURE, (ITextureObject)object); return true; } else { return false; } Where Resources.OTHER_TESTMODEL_CUSTOM is new ResourceLocation(lostworld.lib.References.MODID,"textures/entities/entitytest.png"); ;) ;)
  22. Look, I am creating a Techne like program but inside Minecraft, using Minecraft features. It is working well but I need to refresh texture of the model that I am creating without reloading all minecraft textures.... I am thinking in this possibility: keep a custom.png file inside my mod. When a user clicks my button, I will read the custom.png file from .minecraft\custom.png and replace the ResourceLocation without changing the custom.png file inside my jar file. I am trying to figure out a more basic method to acomplish this, I really don't want to build a lot of code or refresh an entire resource pack just for one texture. I will keep searching and trying methods like these: texturemanager.deleteTexture(MODEL_TEXTURE); Object object = new ThreadDownloadImageData(textureFile, null, MODEL_TEXTURE, new ImageBufferDownload()); texturemanager.loadTexture(MODEL_TEXTURE, (ITextureObject)object); If someone has a new idea, please tell me. I'll appreciate. Thanks †GnR† Slash
  23. I made a GUI where the player can click a button to reload texture. What I want is that the button will load a texture called testmodel.png inside .minecrat folder Every time the user change the texture using Paint.NET, put the texture at this folder and click this button, the texture must be loaded and my mob need to refresh the texture to the new edited one. Any ideas to guid me on this? I think it doesn't matter if the texture will be on a single png file or inside resourcepack, what I really need is to load this new edited texture every time player clicks the button, without the need of restarting minecraft. just read and refresh it on-line Thanks
  24. Hey guys, I am wondering if it is possible to teleport a mob to a custom dimension installed by another mod. I already have mobs teleportation working but only for my dimension... And, another question that I have....... Why portals only teleport players entities and no other creatures? I created a portal that teleports any entities that collided with it and works perfectly... that is a strange face of minecraft behavior lol.
  25. This could be simple, but it will be complex. I think that i should not use sockets or even delay the action inside onItemPickup. I already create a method to segregate things, but it is far away from CreativeTabs groups. Example: how to determine if an item is a weapon? This can't be done without creativeTab information. Look this: isTool = item instanceof ItemTool; isArmor = item instanceof ItemArmor; isPotion = item instanceof ItemPotion; isBlock = item instanceof ItemBlock; isFood = item instanceof ItemFood; There is no "instance of ItemWeapon", and I can't segregate by its material (there is no sense). I still believe that using creativeTabs is the best way to segregate items using built-in Minecraft methods. Please, consider my request. Thanks ps: the mod I am working on is the Simplifier. I created a new item named Auto Bag. Every item that user picks is automatically saved inside these bags, and now, i want to create a way to organize them. This is the link of working version with of Auto Bag (not categorized yet): http://www.minecraftforum.net/topic/1803170-151sspsmpforge-simplifier-made-to-be-easier/
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.