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

Franckyi

Members
  • Posts

    130
  • Joined

  • Last visited

Everything posted by Franckyi

  1. Okay so everything seems to be fine. But I have another problem also linked to networking : my mod can't run on the server. Crash Report It fails when it registers a message that is handled on the client side. But I must register it on both sides anyway, right ? I really don't know where does it try to load the WorldClient class. Is it linked to my special PacketHandler class ? public class PacketHandler { public static abstract class ClientHandler<REQ extends IMessage> extends CommonHandler<REQ> { @Override public IMessage onMessage(REQ message, MessageContext ctx) { super.onMessage(message, ctx); this.world = Minecraft.getMinecraft().world; this.mainThread = Minecraft.getMinecraft(); this.mainThread.addScheduledTask(this); return null; } } public static abstract class CommonHandler<REQ extends IMessage> implements IMessageHandler<REQ, IMessage>, Runnable { protected World world; protected IThreadListener mainThread; protected REQ message; protected MessageContext ctx; @Override public IMessage onMessage(REQ message, MessageContext ctx) { this.message = message; this.ctx = ctx; return null; } } public static abstract class ServerHandler<REQ extends IMessage> extends CommonHandler<REQ> { @Override public IMessage onMessage(REQ message, MessageContext ctx) { super.onMessage(message, ctx); this.world = ctx.getServerHandler().player.world; this.mainThread = (WorldServer) this.world; this.mainThread.addScheduledTask(this); return null; } } public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(ModReference.MODID); } Client-side Message Handlers extends PacketHandler.ClientHandler whereas Server-side Message Handlers extends PacketHandler.ServerHandler.
  2. Thanks ! So this should work ? BlockRedstoneController::breakBlock (everything is called server side) WorldServer worldServer = (WorldServer) world; for (EntityPlayer player : worldServer.playerEntities) { EntityPlayerMP playerMP = (EntityPlayerMP) player; if (worldServer.getPlayerChunkMap() { .getEntry(world.getChunkFromBlockCoords(pos).x, world.getChunkFromBlockCoords(pos).z) .containsPlayer(playerMP)) PacketHandler.INSTANCE.sendTo(new UpdateRedstoneControllerMessage(updateControllers), playerMP); } } (and the same for BlockRedstoneSwitch) EventHandler (I don't know if this event is fired on the server, on client or on both) @SubscribeEvent public void onChunkWatch(ChunkWatchEvent.Watch event) { WorldServer world = event.getPlayer().getServerWorld(); if (!world.isRemote) { for (TileEntity te : world.loadedTileEntityList) { if (event.getChunk().equals(world.getChunkFromBlockCoords(te.getPos()).getPos())) { if (te instanceof TileEntityRedstoneSwitch) { PacketHandler.INSTANCE.sendTo(new UpdateRedstoneSwitchMessage(te.getPos(), te.getCapability(RedstoneSwitchProvider.SWITCH_CAP, null).getSwitch()), event.getPlayer()); } else if (te instanceof TileEntityRedstoneController) { PacketHandler.INSTANCE.sendTo(new UpdateRedstoneControllerMessage(te.getPos(), te.getCapability(RedstoneControllerProvider.CONTROLLER_CAP, null).getController()), event.getPlayer()); } } } } }
  3. I haven't really checked if it was correct or not, but with my new message it works. How do I send a message to the players tracking the chunk ? And also, if player 1 goes far away (not tracking the chunk), then player 2 updates the block, then player 1 comes back, is the data sent automatically to player 1 when he loads the chunk ? Or I have to detect and send the data to the client ?
  4. One solution could be to change the message to send a set of data instead of only one data per message. If someone has a better solution, please tell me. And also, that's strange that I can't send two messages in a too short period of time. [EDIT] My solution works.
  5. My source code is available here : https://github.com/Franckyi/Wireless-Switch-Control/tree/1.11.2-update-networking Network issues are occuring at blocks.BlockRedstoneSwitch::breakBlock and blocks.BlockRedstoneController::breakBlock. In both cases, I'm sending messages to all players in a loop. But, for example, if I send 1, then 2, then 3; I'll recieve 3, 3, 3.
  6. Hi ! I'm using SimpleImpl to send data from the server to the client. I have to send 2 different messages (in fact, the same message containing different informations) approximatively at the same time to all players. But players receive two times the same message. If I pause the server thread after the first message is sent, both messages are correctly received. So I conclude that there's not enough time between the moments where messages are sent. Do you know how can I fix that ?
  7. Exception loading model for variant tardis:blocktardis#normal for blockstate "tardis:blocktardis" There's a problem in your blocktardis.json blockstate file. When looking at the file in you GitHub repo, in this file I see red squares instead of spaces. I don't know what does that mean, but make sure the file is encoded in UTF-8 and also make sure your JSON file is valid. Caused by: java.io.FileNotFoundException: tardis:models/item/blocktardis.json You named your item model itemtardis.json instead of blocktardis.json.
  8. Thanks, I'll try that. Does that means that my BlockState "power" property is useless because I'll directly check the data in the capability ? [EDIT] Yeah, in fact it's not useful to have BlockState properties in my case. I tested and it works very well ! I've overriden TileEntity::markDirty and called World::notifyNeighborsOfStateChange just after that. It should be alright for me, because I always call markDirty() when I change the capability data. Thanks a lot !
  9. Hi ! I'm working on a custom block that can emit redstone signals. The block has a TileEntity. A Capability is attached to this TileEntity. It contains informations like if the block should be sending redstone and with how much power. So consider that my Capability can return a boolean (enabled ? (sending redstone ?)) and an integer (how much power ?). This is my custom block class : public class BlockRedstoneSwitch extends Block { public static final PropertyBool ENABLED = PropertyBool.create("enabled"); public static final PropertyInteger POWER = PropertyInteger.create("power", 0, 15); public BlockRedstoneSwitch(String name, Material mat, CreativeTabs tab, float hardness, float resistance, String tool, int harvest, float light) { super(mat); setUnlocalizedName(name); setRegistryName(name); setCreativeTab(tab); setHardness(hardness); setResistance(resistance); setHarvestLevel(tool, harvest); setLightLevel(light); setDefaultState(this.blockState.getBaseState().withProperty(ENABLED, false).withProperty(POWER, 0)); isBlockContainer = true; } @Override public int getWeakPower(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) { if (state.getValue(ENABLED)) return state.getValue(POWER); return 0; } @Override public boolean canProvidePower(IBlockState state) { return true; } @Override public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) { return state.getValue(ENABLED); } @Override public boolean shouldCheckWeakPower(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) { return false; } @Override public IBlockState getStateFromMeta(int meta) { if (meta > 15) return getDefaultState().withProperty(ENABLED, true).withProperty(POWER, meta - 16); return getDefaultState().withProperty(ENABLED, false).withProperty(POWER, meta); } @Override public int getMetaFromState(IBlockState state) { if(state.getValue(ENABLED)) return state.getValue(POWER) + 16; return state.getValue(POWER); } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] { ENABLED, POWER }); } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { // internal } @Override public boolean hasTileEntity(IBlockState state) { return true; } @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntitySwitch(); } } But I really don't know how to link the Capability data to the BlockState property... It could be updated every tick (is it possible ?) or after a certain method is called on the TileEntity. If someone can help me
  10. Thanks for the answer ! I'll check that and update this topic if I'm in trouble
  11. Hi ! I'm currently saving data to my Block using a TileEntity and the ITileEntityProvider interface. But when a player breaks the block, the TileEntity is removed and the data is lost. I'd like to keep the data in the ItemStack dropped by the block, so when the player replaces it, it'll reload the data previously contained by the TileEntity. 1- Can I do it without using capabilities ? 2- If yes, how/when can I do the conversion from TE data to IS data ? 3- If not, how can I do it using capabilities ?
  12. By definition all 1.x versions are major versions. Major version /=/ Version supported by forge.
  13. Do you have an error ? Does the item appear in the item list (when you use a /give command for example) ? Or is the texture not working ?
  14. Then try to learn Java first, so at least you understand what you're doing and you're not just copying tutorials. [Edit] Faster answers :v
  15. I'd say the same, but without the first slash. Because with it it's an absolute path, and we need a relative path.
  16. Why do you have to test it on the client side ?
  17. Which port are you using ? Default one ? It seems that the port you're using is already used.
  18. It's used to save the data you're changing. In this example, you add or remove cracker, then, you call markDirty(), that means that changes will be written to NBT, so it updates the block in the game. Not exactly sure, but I think it's something like that.
  19. Ahah, was thinking at the same thing ! But well, who cares ? ^^
  20. Ok, then I'll send a packet to the client to get the current note. Thanks !
×
×
  • Create New...

Important Information

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