Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 07/28/20 in all areas

  1. I'm trying to check a player's armor inventory to see if my custom Armor currently has a capability attached to it. If it does in another event I give the player an effect. This works fine in SInglePlayer. However, when I run it in a Dedicated Server, the events are out of sync so the Client Player can see the armor and get the capabilities but the Server Player just returns 0. Is there a better way to get the Player's Armor as an ItemStack? I've tried packets but there's no simple way to return them and putting the information in the Player's Persistent Data causes worse desync problems. I know that player.inventory.armorItemInSlot() can only be run on Client but when I use player.inventory.armorInventory.get() or player.inventory.getStackInSlot() instead it doesn't work on Server. public double getPlayerGemStrength(PlayerEntity player, String attribute) { double fullStrength = 0; for (int i = 0; i < 4; i++) { ItemStack armor; armor = player.inventory.armorItemInSlot(3 - i); LazyOptional<ISlottedArmor> armorCapability = armor.getCapability(SlottedArmorProvider.ARMOR_CAPABILITY); ISlottedArmor armorInstance = armorCapability.orElse(new SlottedArmorInstance()); ItemStack gem = armorInstance.getGem(); if (gem != null) { LazyOptional<IGem> gemCapability = gem.getCapability(GemProvider.GEM_CAPABILITY); IGem gemInstance = gemCapability.orElse(new GemInstance()); String gemAttribute = gemInstance.getAttribute(); double strength = gemInstance.getStrength(); if (gemAttribute != null && !gemAttribute.equals("")) { if (gemAttribute.equals(attribute)) { fullStrength += strength; } } } } return fullStrength; } Here is an example effect: @SubscribeEvent public void giveEffects(PlayerEvent event) { if (event.getPlayer() != null) { PlayerEntity player = event.getPlayer(); double fullStrength = getPlayerGemStrength(player, "HP Up"); if (fullStrength > 0) { MaxHealthHandler.updateHealthModifier(player, fullStrength); } else { MaxHealthHandler.updateHealthModifier(player, 0); } } }
    1 point
  2. I figured it out i was only allowing items to be extracted from slot 2 not 0 or 1.
    1 point
  3. Just adding onto that, if you put your modid into an @ObjectHolder above your class, then any `public static final` fields will be auto-injected with the object according to their fields' name. Again, I refer you to the documentation on this, as it has examples.
    1 point
  4. In the future, please use the code blocks (the `<>` in the editor) when pasting code. You are missing the colon between the modid and item name: "tutorialmod:example_item". That isn't true for annotations on fields; you explicitly need to specify the registry path and, as there is no @ObjectHolder annotation on the class, also the modid/namespace has to be specified. It's all written in the documentation. (see the last example in UnannotatedHolder)
    1 point
  5. Hi! I am creating several items with a random name and want to assign a model to them. In the ModelBakeEvent I register a model for them. And everything works well. But the registry event fires earlier and it spammy my console: [Server-Worker-3/WARN] [minecraft/ModelBakery]: Unable to load model: 'mod:item1#inventory' referenced from: mod:item1#inventory: java.io.FileNotFoundException: mod:models/item/item1.json How can I prevent this? Note: I can't create a .json model because the name is random.
    1 point
  6. I try to assume more clearer. Liahim want to set custom implementation of baked model for some item. This item dont have base json model. Missing of json model is desirable behavior. And he ask: how to remove warnings from log?
    1 point
  7. GREAT.... did you read my fricking response?
    1 point
  8. Ok now I'm seeing anti-patterns Get rid of ModBlock and ModItem, you shouldn't need them. Never use @OnlyIn There's no reason to list your items in a list initializer and then iterate the list You're letting your blocks and items drive their own registration rather than just registering them
    1 point
  9. I have been working on a custom overlay for my mod. It looks like this: but when I open the escape menu it looks like this: My code is this: @OnlyIn(value = Dist.CLIENT) public class ForcePowersOverlay { private Minecraft minecraft; private static final ResourceLocation tex = new ResourceLocation(Reference.MOD_ID, "textures/gui/mod_widgets.png"); public ForcePowersOverlay() { minecraft = Minecraft.getInstance(); } @SubscribeEvent public void renderOverlay(RenderGameOverlayEvent.Post event) { if(event.getType() == RenderGameOverlayEvent.ElementType.ALL) { renderCustomOverlay(); } } private void renderCustomOverlay(){ PlayerEntity player = (PlayerEntity)this.minecraft.getRenderViewEntity(); if (player != null) { IForceSensitive data = player.getCapability(ModCapabilities.FORCE_CAPABILITY).orElseThrow(IllegalStateException::new); int slotX = data.getSlot() * 20; int scaledWidth = this.minecraft.getMainWindow().getScaledWidth(); int scaledHeight = this.minecraft.getMainWindow().getScaledHeight(); RenderSystem.pushMatrix(); RenderSystem.pushTextureAttributes(); RenderSystem.enableAlphaTest(); RenderSystem.enableBlend(); RenderSystem.color4f(1F, 1F, 1F, 1F); minecraft.getTextureManager().bindTexture(tex); //Slots minecraft.ingameGUI.blit(40, scaledHeight - 22, 0, 0, 62, 21); //SelectedSlot minecraft.ingameGUI.blit(40 + slotX, scaledHeight - 23, 62, 0, 24, 22); //Push minecraft.ingameGUI.blit(44, scaledHeight - 18, 4, 25, 15, 15); //Epicenter minecraft.ingameGUI.blit(64, scaledHeight - 18, 23, 25, 15, 15); //Heal minecraft.ingameGUI.blit(84, scaledHeight - 18, 42, 25, 15, 15); //minecraft.getRenderManager().getFontRenderer().drawString(data.getSide().getName(), 8.0f, 6.0f, 410752); minecraft.getTextureManager().bindTexture(AbstractGui.BACKGROUND_LOCATION); RenderSystem.popAttributes(); RenderSystem.popMatrix(); } } Any help would be great thanks.
    0 points
×
×
  • Create New...

Important Information

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