Jump to content

NGYF

Members
  • Posts

    17
  • Joined

  • Last visited

1 Follower

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

NGYF's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. I try to make my custom entity spawn in world. But when I test in Superflat world, my custom entities only spawn in villagers house. Can anybody tell me why, and how to spawn it correctly? Here is the code: OriginiumSlugEntity.java EntitySpawnHandler.java Thank you for your help. By the way, now I need to generate some ore, but I don't know how to start. Could you please tell me how?
  2. Actually, the data changed correctly, but the number showed wrong. When I take away the item it shows the right number immediately. And I can delete some code to make it decrease the same number as 'this.itemStacks.get(i).getCount()' immediately, so I don't think the code runs on the client. But I don't have any idea to solve it. What do you think about it? Thank you.
  3. I've make a new block to craft something, but it has some problems. When I take the result item, the number of material item doesn't appear to decrease. But if I take the material away, the number shows in right way. For example, item A needs 3 item B and 2 item C to craft. When I take away A, number of B and C doesn't change. When I close the block's gui and reopen it or take away B or C, the number decrease properly. The code relevant to the problem is here: public class WorkshopResultSlot extends Slot { private final IItemHandler field_75239_a; private final IInventory transferInv = new Inventory(3); private final PlayerEntity player; private int amountCrafted; public WorkshopRecipe workshopRecipe; public NonNullList<ItemStack> itemStacks = NonNullList.create(); public WorkshopResultSlot(PlayerEntity player, IItemHandler craftingInventory, IInventory inventoryIn, int slotIndex, int xPosition, int yPosition) { super(inventoryIn, slotIndex, xPosition, yPosition); this.player = player; this.field_75239_a = craftingInventory; for(int i = 0; i < 3; i++){ this.transferInv.setInventorySlotContents(i, this.field_75239_a.getStackInSlot(i)); } } //other code... public ItemStack onTake(PlayerEntity thePlayer, ItemStack stack) { this.onCrafting(stack); net.minecraftforge.common.ForgeHooks.setCraftingPlayer(thePlayer); NonNullList<ItemStack> nonnulllist = thePlayer.world.getRecipeManager().getRecipeNonNull(IRecipeTypeArk.WORKSHOP, this.transferInv, thePlayer.world); net.minecraftforge.common.ForgeHooks.setCraftingPlayer(null); for (int i = 0; i < nonnulllist.size(); ++i) { ItemStack itemstack = this.field_75239_a.getStackInSlot(i); ItemStack itemstack1 = nonnulllist.get(i); int count = this.field_75239_a.getStackInSlot(i).getCount(); //=============================== //Belows is the problem code //=============================== for(int j = 0; j < this.itemStacks.size(); ++j) { if (!itemstack.isEmpty()) { if (this.itemStacks.get(j) != null) { if (this.field_75239_a.getStackInSlot(i).getItem() == this.itemStacks.get(j).getItem()) { this.field_75239_a.extractItem(i, this.itemStacks.get(j).getCount(), false); count = this.field_75239_a.getStackInSlot(i).getCount(); itemstack = this.field_75239_a.getStackInSlot(i); System.out.print(this.field_75239_a.getStackInSlot(i).getCount()); //The output is right, but in game the number doesn't change until I take the material item } } } } //==================================== if (!itemstack1.isEmpty()) { if (itemstack.isEmpty()) { this.field_75239_a.insertItem(i, itemstack1, false); } else if (ItemStack.areItemsEqual(itemstack, itemstack1) && ItemStack.areItemStackTagsEqual(itemstack, itemstack1)) { itemstack1.grow(itemstack.getCount()); this.field_75239_a.insertItem(i, itemstack1, false); } else if (!this.player.inventory.addItemStackToInventory(itemstack1)) { this.player.dropItem(itemstack1, false); } } } return stack; } } I mark the problem code. When I delete 'for' and replace 'j' with 'i', the item's number decrease when I take result item, and the decreased number is 'this.itemStacks.get(i).getCount()'. (But it isn't my purpose.) I put the code to github, here is the link: https://github.com/NGYF/Arknights-Mod The java files I think it is necessary: All of https://github.com/NGYF/Arknights-Mod/tree/master/src/main/java/arknights/recipe https://github.com/NGYF/Arknights-Mod/blob/master/src/main/java/arknights/container/WorkshopContainer.java https://github.com/NGYF/Arknights-Mod/blob/master/src/main/java/arknights/tileentity/WorkshopEntity.java Could you tell me how to deal with the problem? Thanks for your help!
  4. Holy shit! I make an very stupid mistake... I forget to add entity to world! That's why I can't find the arrow. I'm so stupid...
  5. I upload the log. Here is one part of the log, it appears when I join the game. It starts at line 16620. [22一月2020 19:05:17.222] [Server thread/INFO] [net.minecraft.server.MinecraftServer/]: Dev加入了游戏 [22一月2020 19:05:17.344] [Render thread/DEBUG] [net.minecraftforge.fml.network.FMLLoginWrapper/FMLHANDSHAKE]: Recieved login wrapper packet event for channel fml:handshake with index -1 [22一月2020 19:05:17.344] [Render thread/ERROR] [net.minecraftforge.fml.network.simple.IndexedMessageCodec/SIMPLENET]: Received empty payload on channel fml:handshake [22一月2020 19:05:18.760] [Server thread/INFO] [net.minecraft.server.integrated.IntegratedServer/]: Saving and pausing game... [22一月2020 19:05:18.985] [Render thread/INFO] [net.minecraft.advancements.AdvancementList/]: Loaded 12 advancements [22一月2020 19:05:19.007] [Server thread/INFO] [net.minecraft.server.MinecraftServer/]: Saving chunks for level 'RhodesIsland'/minecraft:overworld [22一月2020 19:05:19.683] [Server thread/DEBUG] [net.minecraftforge.fml.FMLWorldPersistenceHook/WP]: Gathering id map for writing to world save RhodesIsland [22一月2020 19:05:19.881] [Server thread/DEBUG] [net.minecraftforge.fml.network.FMLLoginWrapper/FMLHANDSHAKE]: Recieved login wrapper packet event for channel fml:handshake with index -1 [22一月2020 19:05:19.881] [Server thread/ERROR] [net.minecraftforge.fml.network.simple.IndexedMessageCodec/SIMPLENET]: Received empty payload on channel fml:handshake The item will send a packet to server when it is left clicked. The method is in BaseItem.java public void emptyLeftClick(PlayerInteractEvent.LeftClickEmpty event){ PacketHandler.HANDLER.sendToServer(new LeftClickPacket()); } And "leftclick" method will be called like this: LeftClickPacket.java package arknights.network.packets; import arknights.item.BaseItem; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketBuffer; import net.minecraftforge.fml.network.NetworkEvent; import java.util.function.Supplier; public class LeftClickPacket { public static void encode(LeftClickPacket msg, PacketBuffer buf){ } public static LeftClickPacket decode(PacketBuffer buf){ return new LeftClickPacket(); } public static class Handler { public static void handle(LeftClickPacket msg, Supplier<NetworkEvent.Context> ctx){ ctx.get().enqueueWork(() -> { PlayerEntity player = ctx.get().getSender(); ItemStack item = player.getHeldItemMainhand(); if(!item.isEmpty() && (item.getItem() instanceof BaseItem)){ ((BaseItem) item.getItem()).leftClick(player, player.getEntityWorld(), item); } }); ctx.get().setPacketHandled(true); } } } leftClick method (inside my item class): public void leftClick(LivingEntity livingEntity, World worldIn, ItemStack stack){ System.out.print("A"); } Does it mean the packet is successfully sent?
  6. private void setup(final FMLCommonSetupEvent event) { PacketHandler.register(); } Should I do it just like this? (The method is in Arknights.java) I'm new to modding... And the problem becomes more and more complicated... I test the mod with out packet handler but it still tells me "Received empty payload on channel fml:handshake". I also test the method leftclick in my item. I add "System.out.print("A"); " to the method, and when I left click, an "A" prints to the terminal. Does it means the packet is succesfully sent? If so, why it doesn't spawn an arrow? Could you tell me how to spawn entities properly?
  7. Maybe I need an example... The former code reference ProjectE, and it use the static initializer. And the documentation is static too. I try to register it in a not static initializer (maybe in a wrong way), and it doesn't work. When I left click, nothing has happened. By the way, the thrown error appears when I join the world, and when I delete the packet registry, it still appears. Here is the code: PacketHandler.java package arknights.network; import arknights.network.packets.LeftClickPacket; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.network.NetworkRegistry; import net.minecraftforge.fml.network.simple.SimpleChannel; public final class PacketHandler { private static final String PROTOCOL_VERSION = Integer.toString(1); public SimpleChannel HANDLER = NetworkRegistry.newSimpleChannel( new ResourceLocation("corruption","main") ,() -> PROTOCOL_VERSION , PROTOCOL_VERSION::equals , PROTOCOL_VERSION::equals); int id = 0; public void register(){ HANDLER.registerMessage(id++, LeftClickPacket.class, LeftClickPacket::encode, LeftClickPacket::decode, LeftClickPacket.Handler::handle); } } Arknights.java Here is the whole class. I think there is something not so relevant, so I provide a simple one. public class Arknights { //something //code I add public static final PacketHandler PACKETHANDLER = new PacketHandler(); public Arknights() { // Register methods for modloading //code I add PACKETHANDLER.register(); // Register ourselves for server and other game events we are interested in } BaseItem.java package arknights.item; import arknights.Arknights; import arknights.network.PacketHandler; import arknights.network.packets.LeftClickPacket; import net.minecraft.entity.LivingEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerInteractEvent; public class BaseItem extends Item { public BaseItem(Properties p_i48487_1_) { super(p_i48487_1_); MinecraftForge.EVENT_BUS.addListener(this::emptyLeftClick); } public void emptyLeftClick(PlayerInteractEvent.LeftClickEmpty event){ Arknights.PACKETHANDLER.HANDLER.sendToServer(new LeftClickPacket()); } public void leftClick(LivingEntity livingEntity, World worldIn, ItemStack stack){ } }
  8. ok. Arknights.java package arknights; import arknights.network.PacketHandler; import arknights.network.packets.LeftClickPacket; import arknights.registry.BlockList; import arknights.registry.ItemHandler; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.item.*; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.InterModComms; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent; import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent; import net.minecraftforge.fml.event.server.FMLServerStartingEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.util.stream.Collectors; // The value here should match an entry in the META-INF/mods.toml file @Mod(Arknights.MODID) public class Arknights { public static final String MODID = "arknights"; // Directly reference a log4j logger. private static final Logger LOGGER = LogManager.getLogger(); public static final ItemGroup ARKNIGHTS = new ItemGroup("arknights") { @Override public ItemStack createIcon() { return new ItemStack(ItemHandler.PUREORIGINIUMS); } }; //Registry Lists private static final BlockList BLOCKLIST = new BlockList(); private static final ItemHandler ITEMLIST = new ItemHandler(); //public static final Block ORIGINIUMS_ORE = new Block(Block.Properties.create(Material.GLASS).hardnessAndResistance(3.0F, 3.0F)).setRegistryName(MODID+":originiums_ore"); //public static final BlockItem ORIGINIUMS_ORE_ITEM = (BlockItem) new BlockItem(ORIGINIUMS_ORE, new Item.Properties().group(ARKNIGHTS)).setRegistryName(MODID+":originiums_ore"); //public static final Item PUREORIGINIUMS = new PureOriginiums(new Item.Properties().group(ARKNIGHTS)).setRegistryName(MODID+":pure_originiums"); public Arknights() { // Register the setup method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); // Register the enqueueIMC method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC); // Register the processIMC method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC); // Register the doClientStuff method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff); FMLJavaModLoadingContext.get().getModEventBus().addListener(PacketHandler::register); // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); } private void setup(final FMLCommonSetupEvent event) { //PacketHandler.HANDLER.registerMessage(PacketHandler.index++, LeftClickPacket.class, LeftClickPacket::encode, LeftClickPacket::decode, LeftClickPacket.Handler::handle); // some preinit code LOGGER.info("HELLO FROM PREINIT"); LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName()); } private void doClientStuff(final FMLClientSetupEvent event) { // do something that can only be done on the client LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings); } private void enqueueIMC(final InterModEnqueueEvent event) { // some example code to dispatch IMC to another mod InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";}); } private void processIMC(final InterModProcessEvent event) { // some example code to receive and process InterModComms from other mods LOGGER.info("Got IMC {}", event.getIMCStream(). map(m->m.getMessageSupplier().get()). collect(Collectors.toList())); } // You can use SubscribeEvent and let the Event Bus discover methods to call @SubscribeEvent public void onServerStarting(FMLServerStartingEvent event) { // do something when the server starts LOGGER.info("HELLO from server starting"); } // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD // Event bus for receiving Registry Events) @Mod.EventBusSubscriber(modid = Arknights.MODID, bus=Mod.EventBusSubscriber.Bus.MOD) public static class RegistryEvents { @SubscribeEvent public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) { // register a new block here for(Block block : BLOCKLIST.blockList){ blockRegistryEvent.getRegistry().register(block); } LOGGER.info("HELLO from Register Block"); } @SubscribeEvent public static void onItemsRegistry(final RegistryEvent.Register<Item> itemRegisterEvent) { for(Item item : BLOCKLIST.blockItemsList){ itemRegisterEvent.getRegistry().register(item); } //MinecraftForge.EVENT_BUS.addListener(ItemHandler::register); ItemHandler.register(itemRegisterEvent); /* for (Item item : ITEMLIST.itemList){ itemRegisterEvent.getRegistry().register(item); }*/ } } } Nothing has changed in other code. Thanks.
  9. Sorry... There is still a strange problem... I add this to my main class, and I think it work. FMLJavaModLoadingContext.get().getModEventBus().addListener(PacketHandler::register); But it still throws an error like this: [08:57:50] [Server thread/ERROR] [ne.mi.fm.ne.si.IndexedMessageCodec/SIMPLENET]: Received empty payload on channel fml:handshake The game will not exit, but there is nothing when I left click my item. Maybe I make some stupid mistakes...
  10. Thank you! Maybe I will complete it today!
  11. Sorry to bother you again. I try to send packets to server when I left click the item, but it throws an error. Here is the error: Here is my code: Please tell me how to fix it. Thanks.
  12. Yes, but maybe I miss something... I'm sorry. Thanks for your patience, I will try it myself.
  13. Thank you. But I'm still a bit confused about handling packets. There are two classes called MyMessage and EntityPlayerMP. I think I should replace EntityPlayerMP with my leftclick class.But if it is right, what does MyMessage refer to? I will appreciate it if you can tell me how to handle packets properly.?
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.