Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Klarks

Members
  • Joined

Everything posted by Klarks

  1. I want to also change a container as well for this gui texture. But how can i use my KeyBinding ?
  2. I found the ivent that calls by key pressing @SubscribeEvent (priority = EventPriority.LOWEST) public static void onClientTick(TickEvent.ClientTickEvent event) throws Exception { if(KEYBIND_ARRAY == null){ KEYBIND_ARRAY = KeyBinding.class.getDeclaredField("KEYBIND_ARRAY"); KEYBIND_ARRAY.setAccessible(true); } if(event.phase.equals(TickEvent.Phase.END)){ Map<String, KeyBinding> binds = (Map<String, KeyBinding>) KEYBIND_ARRAY.get(null); for (String bind : binds.keySet()) { if(binds.get(bind).isKeyDown() && (binds.get(bind) == TEST)){ System.out.println("R"); break; } } } } But i dont understend how i need to code the Container for this and open the gui by press. My Screen class public class NewInvScreen extends ContainerScreen<NewInvContainer> { private ResourceLocation GUI = new ResourceLocation(Main.MODID,"textures/gui/new_inv.png"); public NewInvScreen( PlayerInventory inv, ITextComponent titleIn) { super(null, inv, new TranslationTextComponent("containers.hen.inv")); } @Override public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { this.renderBackground(matrixStack); //this.playerInventoryTitleX = 10; // this.playerInventoryTitleY = 42; super.render(matrixStack, mouseX, mouseY, partialTicks); this.renderHoveredTooltip(matrixStack, mouseX, mouseY); } @Override protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int x, int y) { RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); this.minecraft.getTextureManager().bindTexture(GUI); int i = (this.width - this.xSize) / 2; int j = (this.height - this.ySize) / 2; this.blit(matrixStack, i, j, 0, 0, this.xSize, this.ySize); } @Override protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int x, int y) { this.font.func_243248_b(matrixStack, this.title, (float)10, (float)this.titleY, 4210752); this.font.func_243248_b(matrixStack, this.playerInventory.getDisplayName(), (float)10, (float)42, 4210752); } } Container Class public class NewInvContainer extends Container { private IItemHandler playerInventory; protected NewInvContainer( int id, PlayerInventory playerInventory) { super(NEWINV_CONTAINER.get(), id); this.playerInventory = new InvWrapper(playerInventory); playerInventory.player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(h -> { addSlot(new SlotItemHandler(h,0,79,18)); }); layoutPlayerInventory(7,54); } private int addSlotRange(IItemHandler handler, int index, int x, int y, int amount, int dx) { for(int i = 0; i < amount;i++) { addSlot(new SlotItemHandler(handler,index,x,y)); x+=dx; index++; } return index; } private int addSlotBox(IItemHandler handler,int index,int x,int y,int horAmount,int dx,int verAmount,int dy) { for (int j = 0;j<verAmount;j++) { index = addSlotRange(handler,index,x,y,horAmount,dx); y+=dy; } return index; } private void layoutPlayerInventory(int leftCol, int topRow) { addSlotBox(playerInventory,9,leftCol,topRow,9,18,3,18); topRow += 58; addSlotRange(playerInventory,0,leftCol,topRow,9,18); } @Override public boolean canInteractWith(PlayerEntity playerIn) { return true; } } Screen Manger Registry @Mod.EventBusSubscriber(modid = Main.MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) public class ClientEventBusSubscriber { public static final KeyBinding TEST = new KeyBinding("key.structure.desc", GLFW.GLFW_KEY_R, "key.magicbeans.category"); private static Field KEYBIND_ARRAY = null; @SubscribeEvent public static void clientSetup(FMLClientSetupEvent event) { ScreenManager.registerFactory(RegObj.NEWINV_CONTAINER.get(),NewInvScreen::new); ClientRegistry.registerKeyBinding(TEST); } } Registry public class RegObj { public static final DeferredRegister<ContainerType<?>> CONTAINERS = DeferredRegister.create(ForgeRegistries.CONTAINERS, Main.MODID); public static final RegistryObject<ContainerType<NewInvContainer>> NEWINV_CONTAINER = CONTAINERS.register("newinv", () -> IForgeContainerType.create((windowId, inv,data) -> { World world = inv.player.getEntityWorld(); return new NewInvContainer(windowId,inv); })); //Minecraft.getInstance().player } Main @Mod(Main.MODID) @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public class Main { public static final String MODID = "mymod"; public Main() { IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); RegObj.CONTAINERS.register(bus); } }
  3. I was rewriting my code and have not tested this event yet so I didn't know but will know
  4. I use that way now //edited @Mod.EventBusSubscriber(modid = Main.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class ClientEventBusSubscriber { public static final KeyBinding TEST = new KeyBinding("key.structure.desc", GLFW.GLFW_KEY_R, "key.magicbeans.category"); private static Field KEYBIND_ARRAY = null; @SubscribeEvent (priority = EventPriority.LOWEST) public static void onClientTick(TickEvent.ClientTickEvent event) throws Exception { if(KEYBIND_ARRAY == null){ KEYBIND_ARRAY = KeyBinding.class.getDeclaredField("KEYBIND_ARRAY"); KEYBIND_ARRAY.setAccessible(true); } if(event.phase.equals(TickEvent.Phase.END)){ Map<String, KeyBinding> binds = (Map<String, KeyBinding>) KEYBIND_ARRAY.get(null); for (String bind : binds.keySet()) { if(binds.get(bind).isKeyDown() && (binds.get(bind) == TEST)){ System.out.println("R"); break; } } } } }
  5. MinecraftForge.EVENT_BUS.register(PlayerCapa.class); public class PlayerCapa { @SubscribeEvent (priority = EventPriority.LOWEST) public static void onClientTick(TickEvent.ClientTickEvent event) { } }
  6. https://mcforge.readthedocs.io/en/1.16.x/events/intro/
  7. For some reason, the console doesnt print anything @SubscribeEvent public void onClientTick(TickEvent.ClientTickEvent event) { System.out.println("Hello"); }
  8. Thanks i found it. I'd better use it
  9. I fixed by adding this.playerInventoryTitleY = 42; @Override public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { this.renderBackground(matrixStack); //this.playerInventoryTitleX = 10; this.playerInventoryTitleY = 42; super.render(matrixStack, mouseX, mouseY, partialTicks); this.renderHoveredTooltip(matrixStack, mouseX, mouseY); }
  10. That's not a problem it was just a placeholder. What i should change or add here i couldn't find anything similar in the vanilla code @Override public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { this.renderBackground(matrixStack); super.render(matrixStack, mouseX, mouseY, partialTicks); this.renderHoveredTooltip(matrixStack, mouseX, mouseY); }
  11. Thanks for the tips i made a single stack chest. But how i can fix the inventory title pos and how should i call the lang variable to change the chest name
  12. How can i do it? I don't quite understand what capability is and how to attach it to the player
  13. So itemstack allow to create a bag? I want to make an extra slot for players. Do I need to use an entity for this?
  14. What's the difference between saving per player and itemstacks
  15. Thanks for the tip. How to make a gui as a standard player inventory for storing resources, but with 1 cell. What i should use? I saw tutorials and people uses tileentity, containers but which of this do I need and what function do they perform. I wanna start with simple things
  16. I'm just starting to learn minecraft modding and would like to understand how i can display an empty gui by pressing the key. I tried to figure it out myself from the vanilla minecraft code and tutorials, but I could not understand how it all works
  17. Yes i already did so. Thanks private void setup (final FMLCommonSetupEvent event) { event.enqueueWork(() -> { GlobalEntityTypeAttributes.put(MobEnTypes.GS_COW.get(), gsCowEntity.func_234188_eI_().create()); }); }
  18. Thank you so much it is working now! Thank you! I thought this thing adds the attributes public static AttributeModifierMap.MutableAttribute func_234188_eI_() { return net.minecraft.entity.MobEntity.func_233666_p_().createMutableAttribute(Attributes.MAX_HEALTH, 10.0D).createMutableAttribute(Attributes.MOVEMENT_SPEED, (double)0.2F); }
  19. When i run client i type in the game "/summon mygame.gs_cow" and then minecraft says Unable to summon entity
  20. Please help me to understand what i am doing wrong. I am messing with entities for 3 day and cant fiend any tutorials for 1.16.x that explain how to create just a mob. I try to start with simple thing and recreate a cow but it still doest works package com.klarks.mymod; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @Mod(Main.MODID) @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public class Main { public static final String MODID = "mymod"; public Main() { IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); MobEnTypes.ENTITY_TYPES.register(bus); } } package com.klarks.mymod; import net.minecraft.block.BlockState; import net.minecraft.entity.*; import net.minecraft.entity.ai.attributes.AttributeModifierMap; import net.minecraft.entity.ai.attributes.Attributes; import net.minecraft.entity.ai.goal.*; import net.minecraft.entity.passive.AnimalEntity; import net.minecraft.entity.passive.CowEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.*; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; public class MobEntity extends AnimalEntity { public MobEntity(EntityType<? extends MobEntity> type, World worldIn) { super(type, worldIn); } protected void registerGoals() { this.goalSelector.addGoal(0, new SwimGoal(this)); this.goalSelector.addGoal(1, new PanicGoal(this, 2.0D)); this.goalSelector.addGoal(2, new BreedGoal(this, 1.0D)); this.goalSelector.addGoal(3, new TemptGoal(this, 1.25D, Ingredient.fromItems(Items.WHEAT), false)); this.goalSelector.addGoal(4, new FollowParentGoal(this, 1.25D)); this.goalSelector.addGoal(6, new WaterAvoidingRandomWalkingGoal(this, 1.0D)); this.goalSelector.addGoal(7, new LookAtGoal(this, PlayerEntity.class, 6.0F)); this.goalSelector.addGoal(8, new LookRandomlyGoal(this)); } public static AttributeModifierMap.MutableAttribute func_234188_eI_() { return net.minecraft.entity.MobEntity.func_233666_p_().createMutableAttribute(Attributes.MAX_HEALTH, 10.0D).createMutableAttribute(Attributes.MOVEMENT_SPEED, (double)0.2F); } protected SoundEvent getAmbientSound() { return SoundEvents.ENTITY_COW_AMBIENT; } protected SoundEvent getHurtSound(DamageSource damageSourceIn) { return SoundEvents.ENTITY_COW_HURT; } protected SoundEvent getDeathSound() { return SoundEvents.ENTITY_COW_DEATH; } protected void playStepSound(BlockPos pos, BlockState blockIn) { this.playSound(SoundEvents.ENTITY_COW_STEP, 0.15F, 1.0F); } protected float getSoundVolume() { return 0.4F; } public ActionResultType func_230254_b_(PlayerEntity p_230254_1_, Hand p_230254_2_) { ItemStack itemstack = p_230254_1_.getHeldItem(p_230254_2_); if (itemstack.getItem() == Items.BUCKET && !this.isChild()) { p_230254_1_.playSound(SoundEvents.ENTITY_COW_MILK, 1.0F, 1.0F); ItemStack itemstack1 = DrinkHelper.fill(itemstack, p_230254_1_, Items.MILK_BUCKET.getDefaultInstance()); p_230254_1_.setHeldItem(p_230254_2_, itemstack1); return ActionResultType.func_233537_a_(this.world.isRemote); } else { return super.func_230254_b_(p_230254_1_, p_230254_2_); } } public CowEntity func_241840_a(ServerWorld p_241840_1_, AgeableEntity p_241840_2_) { return EntityType.COW.create(p_241840_1_); } public MobEntity createChild(AgeableEntity ageableEntity) { return MobEnTypes.GS_COW.get().create(this.world); } protected float getStandingEyeHeight(Pose poseIn, EntitySize sizeIn) { return this.isChild() ? sizeIn.height * 0.95F : 1.3F; } } package com.klarks.mymod; import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntityType; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; public class MobEnTypes { public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITIES, Main.MODID); public static final RegistryObject<EntityType<MobEntity>> GS_COW = ENTITY_TYPES .register("gs_cow", () -> EntityType.Builder.<MobEntity>create(MobEntity::new, EntityClassification.CREATURE) .size(0.9f, 1.49f) .build(new ResourceLocation(Main.MODID, "gs_cow").toString())); } package com.klarks.mymod; import net.minecraft.client.renderer.entity.CowRenderer; import net.minecraft.client.renderer.entity.EntityRendererManager; import net.minecraft.client.renderer.entity.MobRenderer; import net.minecraft.client.renderer.entity.model.CowModel; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) public class MobIRender extends MobRenderer<MobEntity, CowModel<MobEntity>> { private static final ResourceLocation COW_TEXTURES = new ResourceLocation("textures/entity/cow/cow.png"); public MobIRender(EntityRendererManager renderManagerIn) { super(renderManagerIn, new CowModel<>(), 0.7F); } public ResourceLocation getEntityTexture(MobEntity entity) { return COW_TEXTURES; } } package com.klarks.mymod; import com.sun.jmx.remote.protocol.rmi.ClientProvider; import net.minecraft.entity.EntityClassification; import net.minecraft.world.biome.Biome; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.eventbus.EventBus; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.client.registry.RenderingRegistry; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.registries.ForgeRegistries; @Mod.EventBusSubscriber(modid = Main.MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) public class ClientEventBusSubscriber { @SubscribeEvent public static void clientSetup(FMLClientSetupEvent event) { RenderingRegistry.registerEntityRenderingHandler(MobEnTypes.GS_COW.get(), MobIRender::new); } @SubscribeEvent public static void onInitBiomesGen(FMLCommonSetupEvent event) { } }

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.