Jump to content

WildHeart

Members
  • Posts

    236
  • Joined

  • Last visited

Everything posted by WildHeart

  1. The problem remained.
  2. Hello, did my liquid, but for some reason the texture is not displayed on the liquid. BlockOil public class BlockOil extends BlockFluidClassic { public BlockOil() { super(new FluidOil(), Material.WATER); setRegistryName("oil"); setUnlocalizedName("oil"); setCreativeTab(TabsHandler.TAB_FLUIDS); } } FluidOil public class FluidOil extends Fluid { public FluidOil() { super("fluidOil", new ResourceLocation("blocks/water_still"), new ResourceLocation("blocks/water_flow")); } @Override public int getColor() { return 0; } } FluidsRegister public class FluidsRegister { public static Fluid OIL = new FluidOil(); public static void register() { FluidRegistry.registerFluid(OIL); } @SideOnly(Side.CLIENT) public static void registerRender() { ModelBakery.registerItemVariants(Item.getItemFromBlock(BlocksRegister.OIL)); ModelLoader.setCustomMeshDefinition(Item.getItemFromBlock(BlocksRegister.OIL), new ItemMeshDefinition() { public ModelResourceLocation getModelLocation(ItemStack stack) { return new ModelResourceLocation("modexample:" + BlocksRegister.OIL.getRegistryName(), "fluid"); } }); ModelLoader.setCustomStateMapper(new BlockOil(), new StateMapperBase() { protected ModelResourceLocation getModelResourceLocation(IBlockState state) { return new ModelResourceLocation("modexample:" + BlocksRegister.OIL.getRegistryName(), "fluid"); } }); } } And oil.json(blockstates) { "forge_marker": 1, "variants": { "fluid": { "model": "forge:fluid", "custom": { "fluid": "fluidOil" } } } } Errors:
  3. so how to solve my problem?
  4. Hello, I draw a circular progress bar and I only got to do a ellipse, but I need a circle. I suggested what to use instead of GL_TRIANGLE_FAN that's GL_LINE_SMOOTH. But there is a problem, if you add GL_LINE_SMOOTH console will be a lot of OpenGL errors. My code: VertexBuffer buf = Tessellator.getInstance().getBuffer(); buf.begin(GL11.GL_TRIANGLE_FAN, DefaultVertexFormats.POSITION_COLOR); buf.pos(PosX, 20, 0).color(0, 0.5F, 0, 1).endVertex(); //Angles = 360, r = 12(radius) for (float i = angles; i > 0; i--) { rad = (i - 90) / 180 * PI; buf.pos(PosX + Math.cos(rad) * r, PosY + Math.sin(rad) * r, 0).color(0, 1, 0, 1).endVertex(); } Tessellator.getInstance().draw(); Error: [08:00:06] [Client thread/ERROR]: ########## GL ERROR ########## [08:00:06] [Client thread/ERROR]: @ Post render [08:00:06] [Client thread/ERROR]: 1280: Invalid enum
  5. As I understand it, I need to send from the server package to the player with data on strength and on the client package has to pass getStamina?
  6. Ok...now that I see the AbstractPacket class I understand what he was doing, I thought it was a vanilla class. I.e., in the package there's nothing to add? Look at loordgek's post for an example of what you are doing specifically. Hmm, not quite what I need sync for the hud, so I can update the progress bar.
  7. I.e., in the package there's nothing to add?
  8. That is explained in the link I sent you. OK, I will ask then as I through the pack to pass to the client player IStamina values? The SimpleNetworkWrapper field you created has methods for sending packets you want SimpleNetworkWrapper#sendTo(IMessage, EntityPlayer) which will send the data to the specific player. I know how to send! How send do I stamina to pass the data inside the package? new StaminaUpdateMessage(stamina); Here: public class PacketStamina extends AbstractPacket<PacketStamina> { @Override public void handleClientSide(PacketStamina message, EntityPlayer player) { } @Override public void handleServerSide(PacketStamina message, EntityPlayer player) { } @Override public void fromBytes(ByteBuf buf) { } @Override public void toBytes(ByteBuf buf) { } }
  9. That is explained in the link I sent you. OK, I will ask then as I through the pack to pass to the client player IStamina values? The SimpleNetworkWrapper field you created has methods for sending packets you want SimpleNetworkWrapper#sendTo(IMessage, EntityPlayer) which will send the data to the specific player. I know how to send! How send do I stamina to pass the data inside the package?
  10. That is explained in the link I sent you. OK, I will ask then as I through the pack to pass to the client player IStamina values?
  11. I have everything you need is there, I don't know how to send values maxStamina, getStamina etc. I know I need to send to the client from the server, but do not know how to send values.
  12. Hello, i have a problem. How to transmit to the client a custom value? I have stamina(for running) and I need to make a progress bar, but I don't know how to convey to the client that I need value.
  13. Hello, I need to spawn the particles from the player, but to see other players and they could spawn the particles. I used to do this: Press "Q" -> sendToAllAround but in this method there is a problem, the players even though I see the particles but when they spanat, they have crashes error to the console(debug). There was another way to do so sendToServer and server side to send the package sendToAllAround, but I simply do not reach the packages. [spoiler=Events] @SubscribeEvent public void onClientTicks(final TickEvent.ClientTickEvent e) { if(e.phase == TickEvent.Phase.START)//For example { NetworkHandler.sendToServer(new PacketParticles()); } } [spoiler=NetworkHandler] public class NetworkHandler { public static final SimpleNetworkWrapper NETWORK = NetworkRegistry.INSTANCE.newSimpleChannel("ModChannel"); private static int dec; public static void init() { NETWORK.registerMessage(PacketParticles.class, PacketParticles.class, dec++, Side.SERVER); NETWORK.registerMessage(PacketFire.class, PacketFire.class, dec++, Side.CLIENT); } public static void sendToAll(final IMessage message) { NETWORK.sendToAll(message); } public static void sendTo(final IMessage message, final EntityPlayerMP player) { NETWORK.sendTo(message, player); } public static void sendToAllAround(final LocationDoublePacket message, final World world) { sendToAllAround(message, message.getTargetPoint(world)); } public static void sendToAllAround(final IMessage message, final NetworkRegistry.TargetPoint point) { NETWORK.sendToAllAround(message, point); } public static void sendToDimension(final IMessage message, final int dimensionId) { NETWORK.sendToDimension(message, dimensionId); } public static void sendToServer(final IMessage message){ NETWORK.sendToServer(message); } } [spoiler=LocationDoublePacket] public abstract class LocationDoublePacket<REQ extends IMessage> extends AbstractPacket<REQ> { protected double x, y, z; public LocationDoublePacket(){} public LocationDoublePacket(final double x, final double y, final double z) { this.x = x; this.y = y; this.z = z; } @Override public void toBytes(final ByteBuf buf) { buf.writeDouble(x); buf.writeDouble(y); buf.writeDouble(z); } @Override public void fromBytes(final ByteBuf buf) { x = buf.readDouble(); y = buf.readDouble(); z = buf.readDouble(); } public NetworkRegistry.TargetPoint getTargetPoint(final World world){ return getTargetPoint(world, 64); } public NetworkRegistry.TargetPoint getTargetPoint(final World world, double updateDistance) { return new NetworkRegistry.TargetPoint(world.provider.getDimension(), x, y, z, updateDistance); } } [spoiler=AbstractPacket] public abstract class AbstractPacket<REQ extends IMessage> implements IMessage, IMessageHandler<REQ, REQ> { @Override public REQ onMessage(final REQ message, final MessageContext ctx) { if(ctx.side == Side.SERVER) { handleServerSide(message, ctx.getServerHandler().playerEntity); } else { handleClientSide(message, FMLClientHandler.instance().getClientPlayerEntity()); } return null; } public abstract void handleClientSide(final REQ message, final EntityPlayer player); public abstract void handleServerSide(final REQ message, final EntityPlayer player); } [spoiler=PacketParticles] public class PacketParticles extends LocationDoublePacket<PacketParticles> { public PacketParticles() { } @Override public void toBytes(final ByteBuf buffer) { } @Override public void fromBytes(final ByteBuf buffer) { } @Override public void handleClientSide(final PacketParticles message, final EntityPlayer player) { } @Override public void handleServerSide(final PacketParticles message, final EntityPlayer player) { NetworkHandler.sendToAllAround(new PacketFire(), player.worldObj); } } [spoiler=PacketFire] public class PacketFire extends LocationDoublePacket<PacketFire> { public PacketFire() { } @Override public void toBytes(final ByteBuf buffer) { } @Override public void fromBytes(final ByteBuf buffer) { } @Override public void handleClientSide(final PacketFire message, final EntityPlayer player) { Vec3d vec = player.getLookVec(); double x = vec.xCoord / 10, y = vec.yCoord / 10, z = vec.zCoord / 10; Random random = new Random(); for (int i = 0; i < 100; i++) { final double xCoord = player.posX + x * i + random.nextDouble(); final double yCoord = player.posY + y * i + random.nextDouble(); final double zCoord = player.posZ + z * i + random.nextDouble(); player.worldObj.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, xCoord, yCoord, zCoord, x * 5, y * 5, z * 5); } } @Override public void handleServerSide(final PacketFire message, final EntityPlayer player) { } }
  14. Good day, doing your inventory with tabs and have run into a problem. If you switch tab on the inventory(previous) and take the item, it disappears and the console shows this error: If you switch tabs then everything is fine(without closing the GUI). After reopening the GUI, the problem persists. Code: [spoiler=Events] [embed=425,349] @SideOnly(Side.CLIENT) @SubscribeEvent public void keys(InputEvent.KeyInputEvent e) { if(!(mc.playerController.isInCreativeMode())) { if (mc.gameSettings.keyBindInventory.isPressed()) PacketHandler.NETWORK.sendToServer(new PacketOpenInventory()); } } @SubscribeEvent public void attachCapabilitiesForEntities(final AttachCapabilitiesEvent.Entity event){ final Entity entity = event.getEntity(); if (entity instanceof EntityPlayer) event.addCapability(CapabilityInventoryProvider.KEY, new CapabilityInventoryProvider((EntityPlayer)entity)); } @SubscribeEvent public void onLivingUpdateEvent(final LivingEvent.LivingUpdateEvent event) { if (!(event.getEntityLiving() instanceof EntityPlayer)) return; final EntityPlayer player = (EntityPlayer) event.getEntityLiving(); if (player == null) return; } @SubscribeEvent public void onDeathEvent(final LivingDeathEvent event) { if(event.getEntityLiving() instanceof EntityPlayer) { final EntityPlayer player = (EntityPlayer)event.getEntityLiving(); if (!player.worldObj.getGameRules().getBoolean("keepInventory")) { final PlayerInventory inventory = player.getCapability(InventoryCapability.CAPABILITY, null); for(int i = 0; i < inventory.getInventory().getStacks().length; i++) { final ItemStack stack = inventory.getInventory().getStacks(); if(stack != null) { player.dropItem(stack, true, false); inventory.getInventory().getStacks() = null; } } } } } @SubscribeEvent public void onClone(final PlayerEvent.Clone event) { if (event.getEntityPlayer().worldObj.getGameRules().getBoolean("keepInventory")) { final PlayerInventory inventory = event.getEntityPlayer().getCapability(InventoryCapability.CAPABILITY, null); final PlayerInventory inventory_original = event.getOriginal().getCapability(InventoryCapability.CAPABILITY, null); final NBTTagCompound tag = (NBTTagCompound) inventory.writeData(); inventory_original.readData(tag); } } @SubscribeEvent public void playerLogin(final net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent event) { if (!event.player.worldObj.isRemote) PacketHandler.NETWORK.sendTo(new PacketInventoryToClient((EntityPlayerMP)event.player), (EntityPlayerMP)event.player); } @SubscribeEvent public void playerChangedDimension(final net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerChangedDimensionEvent event) { if (!event.player.worldObj.isRemote) PacketHandler.NETWORK.sendTo(new PacketInventoryToClient((EntityPlayerMP)event.player), (EntityPlayerMP)event.player); } @SubscribeEvent public void incomingPlayer(final PlayerEvent.StartTracking e) { if(e.getTarget() instanceof EntityPlayer && e.getEntityPlayer() != null) PacketHandler.NETWORK.sendTo(new PacketInventoryPlayer((EntityPlayer) e.getTarget()), (EntityPlayerMP) e.getEntityPlayer()); } [/embed] [spoiler=Packets] [embed=425,349] public class PacketInventoryPlayer implements IMessage { public int otherUser; public ItemStack stack[] = new ItemStack[45]; public PacketInventoryPlayer() {} public PacketInventoryPlayer(EntityPlayer player) { PlayerInventory inv = player.getCapability(InventoryCapability.CAPABILITY, null); otherUser = player.getEntityId(); for (int i = 0; i < stack.length; i++){ stack = inv.getInventory().getStackInSlot(i); } } @Override public void fromBytes(ByteBuf buf) { otherUser = buf.readInt(); for (int i = 0; i < stack.length; i++) stack = ByteBufUtils.readItemStack(buf); } @Override public void toBytes(ByteBuf buf) { buf.writeInt(otherUser); for (int i = 0; i < stack.length; i++) ByteBufUtils.writeItemStack(buf, stack); } public static class PacketInventoryPlayerHandler implements IMessageHandler<PacketInventoryPlayer, IMessage>{ @Override public IMessage onMessage(PacketInventoryPlayer message,MessageContext ctx) { Minecraft.getMinecraft().addScheduledTask( ()->{ EntityPlayer other = (EntityPlayer) Witcher.proxy.getClientWorld().getEntityByID(message.otherUser); if(other != null){ PlayerInventory rpg = other.getCapability(InventoryCapability.CAPABILITY, null); if(rpg != null) for (int i = 0; i < message.stack.length; i++) rpg.getInventory().setStackInSlot(i,message.stack); else FMLLog.getLogger().info("packet info. 'inventory' was null. dropping packet"); }else FMLLog.getLogger().info("packet info. 'other' was null. dropping packet"); }); return null; } } } public class PacketInventoryToClient implements IMessage { public ItemStack stack[] = new ItemStack[45]; public PacketInventoryToClient() { } public PacketInventoryToClient(EntityPlayer player) { PlayerInventory inv = player.getCapability(InventoryCapability.CAPABILITY, null); for(int i = 0; i < stack.length; i ++) stack = inv.getInventory().getStackInSlot(i); } @Override public void fromBytes(ByteBuf buf) { for (int i = 0; i < stack.length; i++){ stack = ByteBufUtils.readItemStack(buf); } } @Override public void toBytes(ByteBuf buf) { for (int i = 0; i < stack.length; i++) { ByteBufUtils.writeItemStack(buf, stack); } } public static class PacketInventoryToClientHandler implements IMessageHandler<PacketInventoryToClient, IMessage>{ @Override public IMessage onMessage(PacketInventoryToClient message,MessageContext ctx) { Minecraft.getMinecraft().addScheduledTask( ()->{ EntityPlayer player = Witcher.proxy.getClientPlayer(); if(player == null) return; PlayerInventory rpg = player.getCapability(InventoryCapability.CAPABILITY, null); for (int i = 0; i < message.stack.length; i++){ rpg.getInventory().setStackInSlot(i,message.stack); } }); return null; } } } public class PacketInventoryToServer implements IMessage { public ItemStack stack[] = new ItemStack[45]; public PacketInventoryToServer() {} public PacketInventoryToServer(EntityPlayer player) { PlayerInventory inv = player.getCapability(InventoryCapability.CAPABILITY, null); for(int i = 0; i < stack.length; i ++) stack = inv.getInventory().getStackInSlot(i); } @Override public void fromBytes(ByteBuf buf) { for (int i = 0; i < stack.length; i++){ stack = ByteBufUtils.readItemStack(buf); } } @Override public void toBytes(ByteBuf buf) { for (int i = 0; i < stack.length; i++) { ByteBufUtils.writeItemStack(buf, stack); } } public static class HandlerPacketInventoryToServer implements IMessageHandler<PacketInventoryToServer, IMessage>{ @Override public IMessage onMessage(PacketInventoryToServer message,MessageContext ctx) { EntityPlayer player = (EntityPlayer)ctx.getServerHandler().playerEntity; WorldServer server = (WorldServer)player.worldObj; server.addScheduledTask( ()->{ PlayerInventory rpg = player.getCapability(InventoryCapability.CAPABILITY, null); for (int i = 0; i < message.stack.length; i++){ rpg.getInventory().setStackInSlot(i,message.stack); } EntityTracker tracker = server.getEntityTracker(); for (EntityPlayer entityPlayer : tracker.getTrackingPlayers(player)){ IMessage packet = new PacketInventoryPlayer(player); PacketHandler.NETWORK.sendTo(packet, (EntityPlayerMP) entityPlayer); } }); return null; } } } public class PacketOpenInventory implements IMessage { public PacketOpenInventory() {} public void fromBytes(ByteBuf buf) {} public void toBytes(ByteBuf buf) {} public static class PacketOpenInventoryHandler implements IMessageHandler<PacketOpenInventory, IMessage> { public IMessage onMessage(PacketOpenInventory message, MessageContext ctx) { ((WorldServer)ctx.getServerHandler().playerEntity.worldObj).addScheduledTask(() -> { EntityPlayerMP player_mp = ctx.getServerHandler().playerEntity; World world = player_mp.worldObj; FMLNetworkHandler.openGui(player_mp, Witcher.instance, GuiHandler.INVENTORY_PLAYER, world, (int)player_mp.posX, (int)player_mp.posY, (int)player_mp.posZ); }); return null; } } } [/embed] [spoiler=GuiHandler] [embed=425,349] public class GuiHandler implements IGuiHandler { public static final int INVENTORY_PLAYER = 0; public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case INVENTORY_PLAYER: return new ContainerTabOne(player, player.getCapability(InventoryCapability.CAPABILITY, null)); default: return null; } } public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case INVENTORY_PLAYER: return new GuiInventoryPlayer(player, player.getCapability(InventoryCapability.CAPABILITY, null)); default: return null; } } } [/embed] [spoiler=Capability] [embed=425,349] public class CapabilityInventoryProvider implements ICapabilitySerializable<NBTTagCompound> { public static final ResourceLocation KEY = new ResourceLocation(Reference.MODID, "tw_player_inventory"); final PlayerInventory slots = new PlayerInventory(); public CapabilityInventoryProvider(EntityPlayer player){ slots.setPlayer(player); } public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if (capability == InventoryCapability.CAPABILITY) return true; return false; } @SuppressWarnings("unchecked") public <T> T getCapability(Capability<T> capability, EnumFacing facing){ if (capability == InventoryCapability.CAPABILITY) return (T)slots; return null; } public NBTTagCompound serializeNBT(){ return (NBTTagCompound) InventoryCapability.CAPABILITY.writeNBT(slots, null); } public void deserializeNBT(NBTTagCompound nbt){ InventoryCapability.CAPABILITY.readNBT(slots, null, nbt); } } public class InventoryCapability { @CapabilityInject(PlayerInventory.class) public static Capability<PlayerInventory> CAPABILITY; public void register() { CapabilityManager.INSTANCE.register(PlayerInventory.class, new StorageHelper(), new DefaultInstanceFactory()); } public static class StorageHelper implements Capability.IStorage<PlayerInventory> { public NBTBase writeNBT(Capability<PlayerInventory> capability, PlayerInventory instance, EnumFacing side) { return instance.writeData(); } public void readNBT(Capability<PlayerInventory> capability, PlayerInventory instance, EnumFacing side, NBTBase nbt) { instance.readData(nbt); } } public static class DefaultInstanceFactory implements Callable<PlayerInventory> { public PlayerInventory call() throws Exception { return new PlayerInventory(); } } } public class PlayerInventory { private StackHandler inventory; private EntityPlayer player; public PlayerInventory() { inventory = new StackHandler(new ItemStack[45]); } public EntityPlayer getPlayer() { return player; } public void setPlayer(EntityPlayer newPlayer) { this.player = newPlayer; } public StackHandler getInventory() { return inventory; } public NBTBase writeData() { NBTTagCompound tag = getInventory().serializeNBT(); return tag; } public void readData(NBTBase nbt) { getInventory().deserializeNBT((NBTTagCompound)nbt); } } public class StackHandler extends ItemStackHandler { public StackHandler(ItemStack[] stack) { super(stack); } public ItemStack[] getStacks() { return stacks; } } [/embed] [spoiler=In GuiInventoryPlayer] [embed=425,349] private void setCurrentCreativeTab(GuiTabs tab) { if (tab == null) return; int i = selectedTabIndex; selectedTabIndex = tab.getTabIndex(); ContainerTabOne containerGui = (ContainerTabOne) this.inventorySlots; EntityPlayer player = Minecraft.getMinecraft().thePlayer; if (tab == GuiTabs.tabInventory) { Container container = new ContainerInventoryPlayer(player.inventory, !player.worldObj.isRemote, player); if (this.originalSlots == null) { this.originalSlots = containerGui.inventorySlots; } containerGui.inventorySlots = container.inventorySlots; } else if (i == GuiTabs.tabInventory.getTabIndex()) { containerGui.inventorySlots = this.originalSlots; this.originalSlots = null; } } [/embed] Also if you have suggestions for improving the code, I'll be glad if you'll help me:)
  15. I found the cause of my problem. It was the fact that when I opened the Gui, went package which opened the container to the other tab and was so that the slots were duplicated. Now the problem seem to be missing. Topic can be deleted/closed.
  16. Well I have the player's inventory and the second tab 45 slots for a category of items. Do you have a Container? Well?
  17. ContainerCP SlotCP
  18. Well I have the player's inventory and the second tab 45 slots for a category of items.
  19. GuiInventoryCP(CustomPlayer)
  20. https://yadi.sk/i/lBlWn59X343cwo <- video file.
  21. Yes! Exactly as there. I looked the code, and there simply is replacing the slots of the container, but my container does not work. Reason: I have things stored in the player, i.e., there are 2 tabs with two containers. In the first tab standard player's inventory, second my container of the player(CapabilitySystem and etc)
  22. I need to open a gui depending on the tab container.
  23. Good afternoon, I have one GUI open at the beginning of one container, then another. How to implement?
×
×
  • Create New...

Important Information

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