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


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by deerangle

  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. 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?
  4. 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.
  5. 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.
  6. 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()); } }
  7. 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()); }); } } } } } }
  8. Honestly, I'm ashamed that that using an event isn't the first thing I thought of... ?
  9. 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")
  10. 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); }
  11. 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?
  12. Works like a charm and was way easier than copying the entire SignTileEntity class. Thanks for your help!
  13. 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.
  14. I'm a little confused on how to do this, as the signature of the constructor for SignTileEntity is this: public SignTileEntity() { super(TileEntityType.SIGN); } So I can't pass my own TileEntityType to it.
  15. I want to create a custom sign block. Ideally, I could just add my Sign blocks to the existing TileEntityType SIGN. Is that possible, or do I have to make my own TileEntity?
  16. That worked fine, and thanks for the info about DistExecutor.
  17. Weirdly, when I inline the World in this part of the code World world = Minecraft.getInstance().world; TileEntity te = world.getTileEntity(message.pos); the error disappears... But that isn't really a fix to the problem, as in some situations, inlining might not be possible. What can I do to fix this error without inlining?
  18. have a look at this: http://jabelarminecraft.blogspot.com/p/minecraft-forge-1721710-keybinding.html
  19. I have a packet that goes to the client in my code, that the server is for some reason trying to load... This causes a crash with this error: [19:41:39] [Server thread/ERROR] [minecraft/MinecraftServer]: Encountered an unexpected exception net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [ Laser Mod (lasermod) encountered an error during the common_setup event phase §7Attempted to load class net/minecraft/client/world/ClientWorld for invalid dist DEDICATED_SERVER ] at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:201) ~[?:?] {re:classloading} at net.minecraftforge.fml.ModLoader.loadMods(ModLoader.java:154) ~[?:?] {re:classloading} at net.minecraftforge.fml.server.ServerModLoader.begin(ServerModLoader.java:46) ~[?:?] {re:classloading} at net.minecraft.server.dedicated.DedicatedServer.init(DedicatedServer.java:124) ~[?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:622) [?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A} at java.lang.Thread.run(Thread.java:748) [?:1.8.0_222] {} Here is where I reference a ClientWorld in my code: public static void handle(PacketLaserLensUpdate message, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { World world = Minecraft.getInstance().world; TileEntity te = world.getTileEntity(message.pos); if (te instanceof LaserTileEntity) { LaserTileEntity laser = (LaserTileEntity) te; laser.color = message.color; laser.direction = message.direction; laser.maxDistance = message.distance; laser.thickness = message.thickness; laser.active = message.active; } })); ctx.get().setPacketHandled(true); } As you can see I tried using DistExecutor, but that isn't working for some reason. Im registering the packets in the FMLCommonSetupEvent.
  20. In my mod, I have a TileEntity with a TESR that renders outside of the block bounds. So now, when the block bounds isn't in frame, the block doesn't render at all. Beacons for example have the Beacon Ray which is rendered even when not looking at the beacon. I tried using this code to get it working, but I had no success: @Override public boolean isGlobalRenderer(LaserTileEntity te) { return true; }
  21. Fixed it by changing the bake method in the MultiLayerModel (or LensModel in my case) to get BlockModels instead of VariantLists. BlockModels can be rotated, and that's why It's now working
  22. Since I copied most of the code for the GradientFontRenderer from the original FontRenderer, which is decompiled and therefore doesn't use hex literals, the color values are in decimal.
  • Create New...

Important Information

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