Jump to content

aetherean

Members
  • Posts

    16
  • Joined

  • Last visited

aetherean's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Nevermind, please ignore -- ended up implementing this with custom packets.
  2. Hi, I'd like to implement a very simple state machine for two clients connected to an integrated server. Keypresses on one client should update some boolean values that would affect the capabilities of the other client until that client responds with some keypresses of their own, and the state transitions based on these booleans would ideally be implemented by some independent state machine. However, I'm not understanding how/where to construct the state machine that would maintain these boolean values without the each client just constructing their own and never seeing updates from the other player. (Rather, it's not clear to me where in the initialization routine integrated-server-only code runs -- not considering using a dedicated server at the moment.) What would be the easiest way to go about implementing this? Thanks in advance.
  3. Ah, thank you!! It seems to work now with the following changes: @SubscribeEvent public void onItemPickup(EntityItemPickupEvent event) { if (!event.getEntity().getEntityWorld().isRemote && event.getEntity() instanceof EntityPlayerMP) { EntityPlayerMP player = (EntityPlayerMP) event.getEntityPlayer(); System.out.println("Item " + event.getItem().getName() + " picked up by " + player.getName()); if (event.getItem().getEntityItem().getItem() != Items.AIR) { int slot = player.inventory.getSlotFor(event.getItem().getEntityItem()); int empty = player.inventory.getFirstEmptyStack(); player.inventory.currentItem = InventoryPlayer.isHotbar(slot) ? slot : empty < 0 ? player.inventory.currentItem : empty; player.connection.sendPacket(new SPacketHeldItemChange(player.inventory.currentItem)); } } } If anything seems amiss that I've overlooked, please let me know. On the surface, the behavior seems to be correct. (Specifically event.getItem().getEntityItem().getItem() seems really roundabout but that was the way I could get the typing to work out...) I originally kept detectAndSendChanges() and also player.sendContainerToPlayer(player.inventoryContainer); as done in PlayerList but it seems it wasn't needed (unless it actually is needed behind-the-scenes and I should add it back).
  4. Hi, I would like to implement the behavior that if an item is picked up, it is immediately switched to be the current item held by that player (and the hotbar should reflect this). I've tried playing around with the EntityItemPickupEvent but it seems like I'm not quite handling the server/client stuff for player inventory properly. What would be the best way to do this? Here's what I have so far, which seems to work correctly server-side but the client GUI is not reflecting the changes properly: @SubscribeEvent public void onItemPickup(EntityItemPickupEvent event) { if (!event.getEntity().getEntityWorld().isRemote && event.getEntity() instanceof EntityPlayer) { EntityPlayer player = event.getEntityPlayer(); System.out.println("Item " + event.getItem().getName() + " picked up by " + player.getName()); if (!event.getItem().getName().equals("item.tile.air")) { player.inventory.currentItem = player.inventory.getSlotFor(event.getItem().getEntityItem()); player.inventoryContainer.detectAndSendChanges(); } } } Thanks in advance.
  5. From what I understand (I'm not in charge of the multiplayer stuff), so far we've been debugging by having two clients on localhost, one of whom joins the server that the other spawns on. In the future, we'll probably want to do this via LAN to support connecting from multiple machines. I don't think there are any plans of using a dedicated server. The mod does run in this setup -- my custom blocks and such work fine.
  6. @AnZaNaMa going back to debugging the flying/invulnerability code upon agent startup, we realized that these player capabilities aren't enabled when in a multiplayer setting (though it seems the event handler still fires). Is sendPlayerAbilities() single-player only? Or is there some extension to this code I should add?
  7. I am creating a world where the only blocks that can be destroyed are my defined blocks, starting with a limited quantity of each in the player's inventory. Effectively there won't be any other blocks that should be able to be added to the player's hotbar. I am also trying to force the player to have to reselect the inventory slot of the block they'd like to place if they wanted to place more than one block at a time. It's more tedious for the player, but the world we're trying to simulate is one where you'd have to pick up a block (either by picking up in the world or selecting explicitly from your inventory) every time you want to place one, instead of blocks magically appearing in your hand. Sorry if this use case seems confusing. For context, we're trying to use this for data collection in an environment that behaves fundamentally differently from Minecraft, but a lot of the elements (e.g. blocks, limited resources, structure building) are similar enough that we'd like to use Minecraft as a base for simulation.
  8. Ohh, got it! It works now, thanks so much. Clearly I need to spend a little more time with Forge events and the server/client relationship. If you don't mind, can I pick your brain on another thing? I'd like to have this kind of behavior when destroying/placing blocks: on destroy, auto-pickup the dropped block and switch the item being held to that block; on place, stop holding the item (even if you have remaining quantities of that item in your inventory). In essence, I'm trying to be able to emulate "moving" blocks in the world by picking them up into your hand and putting them down. I'm not too familiar with how the inventory/hand are represented client/server-wise -- is this something I can do on the client side only, or do I need to also do something server-side?
  9. Whooops totally just saw that I was setting isFlying instead of allowFlying. But alas, still no flying
  10. Thanks for all the help. I ended up making an event handler as follows: @SubscribeEvent public void onPlayerLogin(net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent event) { event.player.capabilities.isFlying = true; event.player.capabilities.disableDamage = true; System.out.println("Logged in"); } using PlayerLoggedInEvent instead of your join world/respawn events. I'm still confused, though -- I know the event is being caught because the printline shows up, but I'm still unable to fly and I still take damage.
  11. Ahh, okay, makes sense. In which part of my code do I set these fields? I tried to do so during initialization but Minecraft.getMinecraft().player seem to be null. Not sure how to access the player properly and when.
  12. Is there a reason I shouldn't? Does it break things fundamentally somehow? I need an environment where players can freely fly and build structures, but only using my predefined blocks and with a limited quantity. If I should use a different mode, how would I achieve this?
  13. I see, thanks for the input. Then in order to get the behavior I need in Creative mode (destroying a block adds to your item stack in the inventory of that item, while placing blocks consumes one of the items in that stack), what would be easiest? Should I look into modifying the behavior of the block's destroy function? Harvest function + auto-pickup for drops? Or is limited resources a thing I can enable in Creative and I'm just not savvy enough with Minecraft to know about it?
  14. I'm trying to simulate an environment in which users can pick up/set down blocks from a limited quantity (instead of "destroying" blocks that is traditionally done), while still being able to make structures in Creative mode while flying around. I'm trying to use Minecraft as a base where users feel like they're "playing with toy blocks" rather than "playing Minecraft," if that makes sense. Does it make sense to approach it from this way? Or should I instead do something like overriding the "destroy" block functions instead of "pick block"?
  15. Hello, I'm very new to Minecraft Forge modding and Minecraft in general, so please excuse my ignorance. I'm trying to define the behavior of my custom block such that when it is picked in Creative, it will disappear from the world (but the item will be placed in your hand as it would with normal picking of blocks). I would also like to increment its inventory count when it is picked (and similarly decrement it when it is placed). I've been trying to go about this by overriding the getPickBlock method definition and using within it world.setBlockToAir(pos), but from what I understand, getPickBlock is never called server-side, so I run into the problem of still colliding with air when blocks are picked. I don't quite understand the server-client relationship -- where should I be trying to do this instead? Or, is there a better solution? My (wrong) code: @Override public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) { player.inventory.setPickedItemStack(getItem(world, pos, state)); player.inventory.getCurrentItem().grow(1); world.setBlockToAir(pos); return getItem(world, pos, state); } Thanks in advance.
×
×
  • Create New...

Important Information

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