Jump to content

deerangle

Members
  • Posts

    259
  • Joined

  • Last visited

  • Days Won

    1

deerangle last won the day on January 26 2019

deerangle had the most liked content!

1 Follower

Converted

  • Gender
    Undisclosed
  • Personal Text
    I love Minecraft Forge!

Recent Profile Visitors

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

deerangle's Achievements

Diamond Finder

Diamond Finder (5/8)

17

Reputation

  1. Fixed by using this.getWorld().func_234923_W_()
  2. I want to send a packet to all players near my tileentity in the current dimension: PacketHandler.INSTANCE.send(PacketDistributor.NEAR.with(PacketDistributor.TargetPoint.p(pos.getX(), pos.getY(), pos.getZ(), 64, ???)), new RqUpdateWandTablePacket(getPos())); What do I use for the dimension? it requires a RegistryKey<World> . How do I get that?
  3. I think it's working now. Thanks for your help
  4. How do I make sure Itemstack#getTag doesn't return null every time? How do I make my Item have a tag? I'm not sure what to use. Should I call getOrCreateTag somewhere?
  5. I have made an Item that has a Capability. I can use the capability without issues for the most part. The data persists on save/load world too. However, when I change the ItemStack (move it to another slot) when running dedicated server and client, the data just disappears. Here is the Item class: public class LaptopItem extends Item { private static final ITextComponent containerName = new TranslationTextComponent("container.rubymod.laptop"); public LaptopItem(Properties group) { super(group); } @Nullable @Override public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) { if (ComputerHolderProvider.CAPABILITY != null) { return new ComputerHolderProvider(); } return super.initCapabilities(stack, nbt); } @Nullable @Override public CompoundNBT getShareTag(ItemStack stack) { CompoundNBT tag = new CompoundNBT(); stack.getCapability(ComputerHolderProvider.CAPABILITY).ifPresent(cap -> { UUID computer = cap.getComputer(); if (computer != null) { tag.putString("Computer", computer.toString()); } }); return tag; } @Override public void readShareTag(ItemStack stack, @Nullable CompoundNBT nbt) { stack.getCapability(ComputerHolderProvider.CAPABILITY).ifPresent(cap -> { if (nbt != null) { String uidString = nbt.getString("Computer"); if (uidString.length() > 0) { cap.setComputer(UUID.fromString(uidString)); } } }); } @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity player, Hand handIn) { if (worldIn.isRemote) { return ActionResult.resultSuccess(player.getHeldItem(handIn)); } else { ItemStack stack = player.getHeldItem(handIn); stack.getCapability(ComputerHolderProvider.CAPABILITY).ifPresent(cap -> { UUID computer = cap.getComputer(); INamedContainerProvider containerProvider = new SimpleNamedContainerProvider( (windowId, inventory, _player) -> new ComputerContainer(windowId, inventory, computer), containerName); NetworkHooks.openGui((ServerPlayerEntity) player, containerProvider, packetBuffer -> packetBuffer.writeUniqueId(computer)); }); // TODO: add stats // player.addStat(Stats.INTERACT_WITH_LAPTOP); return ActionResult.resultSuccess(player.getHeldItem(handIn)); } } @Override public void inventoryTick(ItemStack stack, World world, Entity entityIn, int itemSlot, boolean isSelected) { if (!world.isRemote) { stack.getCapability(ComputerHolderProvider.CAPABILITY).ifPresent(cap -> { world.getCapability(ComputerStorageProvider.CAPABILITY).ifPresent(cap2 -> { Computer comp = cap2.getOrCreateComputer(cap.getComputer()); comp.clock(); }); }); } } } I read in some other thread that syncing the data between client and server using getShareTag is supposed to fix this, however that didn't work for me. I suspect that something is wrong with the syncing code (it appears that the CompoundNBT in readShareTag is null.
  6. During initialization. I just updated my workspace from 31.1.45 to 31.1.46. It's working now (fires when loading the world). I don't know if it was the version bump that fixed it, but probably It was not firing because I wasn't loading a world. Anyway, it's working now and I can access the capability.
  7. I was trying to add a capability, but for some reason, the AttachCapabilitiesEvent isn't being fired (checked with breakpoints). I checked multiple times but couldn't find anything wrong with my Event handler. Here is the relevant code: @Mod.EventBusSubscriber(bus= Mod.EventBusSubscriber.Bus.FORGE, modid=RubyMod.MODID) public class ForgeRegistry { public static final ResourceLocation COMPUTER_STORAGE_CAP = new ResourceLocation(RubyMod.MODID, "computer_storage"); @SubscribeEvent public static void onAttachCapabilities(AttachCapabilitiesEvent<TileEntity> event) { event.addCapability(COMPUTER_STORAGE_CAP, new ComputerStorageProvider()); } }
  8. For anyone interested in using the Event method in favor of Reflection: public class EventHandler { public static Map<Block, Block> BLOCK_STRIPPING_MAP = new HashMap<>(); static { BLOCK_STRIPPING_MAP.put(Registry.BEECH_LOG_BLOCK, Registry.STRIPPED_BEECH_LOG_BLOCK); BLOCK_STRIPPING_MAP.put(Registry.BEECH_WOOD_BLOCK, Registry.STRIPPED_BEECH_WOOD_BLOCK); } @SubscribeEvent public static void onBlockClicked(PlayerInteractEvent.RightClickBlock event) { if (event.getItemStack().getItem() instanceof AxeItem) { World world = event.getWorld(); BlockPos blockpos = event.getPos(); BlockState blockstate = world.getBlockState(blockpos); Block block = BLOCK_STRIPPING_MAP.get(blockstate.getBlock()); if (block != null) { PlayerEntity playerentity = event.getPlayer(); world.playSound(playerentity, blockpos, SoundEvents.ITEM_AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F); if (!world.isRemote) { world.setBlockState(blockpos, block.getDefaultState() .with(RotatedPillarBlock.AXIS, blockstate.get(RotatedPillarBlock.AXIS)), 11); if (playerentity != null) { event.getItemStack().damageItem(1, playerentity, (p_220040_1_) -> { p_220040_1_.sendBreakAnimation(event.getHand()); }); } } } } } }
  9. Honestly, I'm ashamed that that using an event isn't the first thing I thought of... ?
  10. I used the following field name to get this to work (also when building and running outside of the development environment): ObfuscationReflectionHelper.findField(AxeItem.class, "field_203176_a")
  11. I was facing the same problem in my mod. I used the following solution: private static void addStripping() throws NoSuchFieldException, IllegalAccessException { Field map = ObfuscationReflectionHelper.findField(AxeItem.class, "BLOCK_STRIPPING_MAP"); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(map, map.getModifiers() & ~Modifier.FINAL); map.setAccessible(true); Map<Block, Block> strip_map = (Map<Block, Block>) map.get(null); HashMap<Block, Block> new_map = new HashMap<>(strip_map); new_map.put(Registry.BEECH_LOG_BLOCK, Registry.STRIPPED_BEECH_LOG_BLOCK); new_map.put(Registry.BEECH_WOOD_BLOCK, Registry.STRIPPED_BEECH_WOOD_BLOCK); map.set(null, new_map); }
  12. I have a log block in my mod, and I want to make it possible to strip when right-clicked with an axe. Currently, I am using this horrible method with reflection: private static void addStripping() throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException { Class clazz = Class.forName("net.minecraft.item.AxeItem"); Field map = clazz.getDeclaredField("BLOCK_STRIPPING_MAP"); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(map, map.getModifiers() & ~Modifier.FINAL); map.setAccessible(true); Map<Block, Block> strip_map = (Map<Block, Block>) map.get(null); HashMap<Block, Block> new_map = new HashMap<>(strip_map); new_map.put(Registry.BEECH_LOG_BLOCK, Registry.STRIPPED_BEECH_LOG_BLOCK); new_map.put(Registry.BEECH_WOOD_BLOCK, Registry.STRIPPED_BEECH_WOOD_BLOCK); map.set(null, new_map); } Is there any other way to do this?
  13. Works like a charm and was way easier than copying the entire SignTileEntity class. Thanks for your help!
  14. public class BeechSignTileEntity extends SignTileEntity { public BeechSignTileEntity() { super(Registry.SIGN_TE); // doesn't work } } I made my own TileEntity. I extended SignTileEntity. However, I can't pass my TileEntityType to the superconstructor because the superconstructor doesn't accept a TileEntityType.
×
×
  • Create New...

Important Information

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