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 get it but my container have a data parametr now protected MyModContainer(int id, PlayerInventory playerInventory,World world,PacketBuffer data) { super(RegObj.MOD_CONTAINER.get(), id); this.playerInventory = new InvWrapper(playerInventory); world.getEntityByID( data.readInt()).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(h -> { addSlot(new SlotItemHandler(h,0,79,18)); }); layoutPlayerInventory(7,54); } and my anonymous inner class asks for data parametr too. if i'll leave it null container wont work INamedContainerProvider iNamedContainerProvider = new INamedContainerProvider() { @Override public ITextComponent getDisplayName() { return new StringTextComponent("loh"); } @Nullable @Override public Container createMenu(int id, PlayerInventory playerInventory, PlayerEntity playerEntity) { return new MyModContainer(id,playerInventory, world,extraDataWriter); } };
  2. Thanks it seems to be working. But i didnt understand one thing. if this line sending the EntityId to my container return new MyModContainer(id,playerInventory, world,extraDataWriter); so what do that line with EntityId NetworkHooks.openGui((ServerPlayerEntity) playerEntity,iNamedContainerProvider, buf -> buf.writeInt(getEntityId())); PacketBuffer extraDataWriter = new PacketBuffer(Unpooled.buffer()); extraDataWriter.writeInt(getEntityId()); INamedContainerProvider iNamedContainerProvider = new INamedContainerProvider() { @Override public ITextComponent getDisplayName() { return new StringTextComponent("loh"); } @Nullable @Override public Container createMenu(int id, PlayerInventory playerInventory, PlayerEntity playerEntity) { return new MyModContainer(id,playerInventory, world,extraDataWriter); } }; NetworkHooks.openGui((ServerPlayerEntity) playerEntity,iNamedContainerProvider, buf -> buf.writeInt(getEntityId()));
  3. When i tranna locate my structure minecraft says "Could not find that structure nearby ". What i did wrong public class MyStructure { public static final DeferredRegister<Structure<?>> DEFERRED_REGISTRY_STRUCTURE = DeferredRegister.create(ForgeRegistries.STRUCTURE_FEATURES, Main.MODID); public static final RegistryObject<Structure<NoFeatureConfig>> RUN_DOWN_HOUSE = registerStructure("run_down_house", () -> (new MyPieces(NoFeatureConfig.field_236558_a_))); private static <T extends Structure<?>> RegistryObject<T> registerStructure(String name, Supplier<T> structure) { return DEFERRED_REGISTRY_STRUCTURE.register(name, structure); } public static void setupStructures() { setupMapSpacingAndLand( RUN_DOWN_HOUSE.get(), new StructureSeparationSettings(10 , 5 , 1234567890 ), true); } public static <F extends Structure<?>> void setupMapSpacingAndLand( F structure, StructureSeparationSettings structureSeparationSettings, boolean transformSurroundingLand) { Structure.NAME_STRUCTURE_BIMAP.put(structure.getRegistryName().toString(), structure); if(transformSurroundingLand) Structure.field_236384_t_.add(structure); DimensionStructuresSettings.field_236191_b_.put(structure, structureSeparationSettings); } public class MyPieces extends Structure<NoFeatureConfig> { public MyPieces(Codec<NoFeatureConfig> codec) { super(codec); } @Override public IStartFactory<NoFeatureConfig> getStartFactory() { return MyPieces.Start::new; } @Override public GenerationStage.Decoration getDecorationStage() { return GenerationStage.Decoration.SURFACE_STRUCTURES; } public static class Start extends StructureStart<NoFeatureConfig> { public Start(Structure<NoFeatureConfig> p_i225876_1_, int p_i225876_2_, int p_i225876_3_, MutableBoundingBox p_i225876_4_, int p_i225876_5_, long p_i225876_6_) { super(p_i225876_1_, p_i225876_2_, p_i225876_3_, p_i225876_4_, p_i225876_5_, p_i225876_6_); } @Override public void func_230364_a_(DynamicRegistries dynamicRegistries, ChunkGenerator chunkGenerator, TemplateManager templateManager, int cx, int cy, Biome biome, NoFeatureConfig config) { int x = cx << 4; int z = cy << 4; BlockPos blockpos = new BlockPos(x, 0, z); JigsawManager.func_242837_a( dynamicRegistries,new VillageConfig(() -> dynamicRegistries.getRegistry(Registry.JIGSAW_POOL_KEY).getOrDefault(new ResourceLocation(Main.MODID,"run_down_house/start_pool")),10), AbstractVillagePiece::new,chunkGenerator,templateManager,blockpos,this.components,this.rand,false,true); this.components.forEach(piece -> piece.offset(0, 1, 0)); this.components.forEach(piece -> piece.getBoundingBox().minY -= 1); this.recalculateStructureSize(); } } } public class MyConfigStructures { public static StructureFeature<?, ?> CONFIGURED_RUN_DOWN_HOUSE = MyStructure.RUN_DOWN_HOUSE.get().withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG); public static void registerConfiguredStructures() { Registry<StructureFeature<?, ?>> registry = WorldGenRegistries.CONFIGURED_STRUCTURE_FEATURE; Registry.register(registry, new ResourceLocation(Main.MODID, "configured_run_down_house"), CONFIGURED_RUN_DOWN_HOUSE); Map<Structure<?>, StructureFeature<?, ?>> STR = ObfuscationReflectionHelper.getPrivateValue(FlatGenerationSettings.class,null,"STRUCTURES"); STR.put(MyStructure.RUN_DOWN_HOUSE.get(), CONFIGURED_RUN_DOWN_HOUSE); ObfuscationReflectionHelper.setPrivateValue(FlatGenerationSettings.class,null,STR,"STRUCTURES"); //Map<Structure<?>, StructureFeature<?, ?>> STR = ObfuscationReflectionHelper.getPrivateValue(FlatGenerationSettings.class,null,"field_202247_j"); //STR.put(MyStructure.RUN_DOWN_HOUSE.get(), CONFIGURED_RUN_DOWN_HOUSE); //ObfuscationReflectionHelper.setPrivateValue(FlatGenerationSettings.class,null,STR,"field_202247_j"); } } public Main() { IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); MyStructure.DEFERRED_REGISTRY_STRUCTURE.register(bus); bus.addListener(this::setup); IEventBus forgeBus = MinecraftForge.EVENT_BUS; forgeBus.addListener(EventPriority.NORMAL, this::addDimensionalSpacing); forgeBus.addListener(EventPriority.HIGH, this::biomeModification); } private void setup (final FMLCommonSetupEvent event) { Networking.RegMes(); event.enqueueWork(() -> { MyStructure.setupStructures(); MyConfigStructures.registerConfiguredStructures(); }); } public void biomeModification(final BiomeLoadingEvent event) { event.getGeneration().getStructures().add(() -> MyConfigStructures.CONFIGURED_RUN_DOWN_HOUSE); } public void addDimensionalSpacing(final WorldEvent.Load event) { if(event.getWorld() instanceof ServerWorld){ ServerWorld serverWorld = (ServerWorld)event.getWorld(); if(serverWorld.getChunkProvider().getChunkGenerator() instanceof FlatChunkGenerator && serverWorld.getDimensionKey().equals(World.OVERWORLD)){ return; } Map<Structure<?>, StructureSeparationSettings> tempMap = new HashMap<>(serverWorld.getChunkProvider().generator.func_235957_b_().func_236195_a_()); tempMap.put(MyStructure.RUN_DOWN_HOUSE.get(), DimensionStructuresSettings.field_236191_b_.get(MyStructure.RUN_DOWN_HOUSE.get())); serverWorld.getChunkProvider().generator.func_235957_b_().func_236195_a_(); }
  4. I don't understand. Where i should have container factory
  5. In my IContainerFactory? Where i can get it in my container class
  6. is it correct? //MyModEntity public ITextComponent getDisplayName() { return new StringTextComponent("Name"); } @Nullable @Override public Container createMenu(int id, PlayerInventory playerInventory, PlayerEntity playerEntity) { return new MyModContainer(id,playerInventory, world); } }; PacketBuffer buf = new PacketBuffer(Unpooled.buffer()); buf.writeVarInt(this.getEntityId()); NetworkHooks.openGui((ServerPlayerEntity) playerEntity,iNamedContainerProvider,(Consumer<PacketBuffer> buf); and how can i get it in my container class //MyModContainer world.getEntityByID().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(h -> { addSlot(new SlotItemHandler(h,0,79,18)); });
  7. Is STRUCTURES a mapped name? forge-bot gave me this MC 1.16.3: net/minecraft/world/gen/FlatGenerationSettings.STRUCTURES Name: c => field_202247_j => STRUCTURES Comment: None Side: BOTH AT: public net.minecraft.world.gen.FlatGenerationSettings field_202247_j # STRUCTURES
  8. Ok i messed up few things, idk where did i get a player inventory parameter in openGui. So thanks it's working now But how i can correctly get the entity inside the container class to get capabilities to add a slot. I know how to do it with the player i can just get the player from the player inventory but with a mob i am not sure. Should i get the entity from world somehow?
  9. With out it java gave an error "Cant resolve method openGui". What i did wrong here?
  10. is it correct INamedContainerProvider in = new INamedContainerProvider() { @Override public ITextComponent getDisplayName() { return new StringTextComponent("Name"); } @Nullable @Override public Container createMenu(int id, PlayerInventory playerInventory, PlayerEntity playerEntity) { return new MyModContainer(id,playerInventory); } }; if(en.equals(pl)) { NetworkHooks.openGui((ServerPlayerEntity) playerEntity, in,(Consumer<PacketBuffer>) playerEntity.inventory); } else playerEntity.sendMessage(new TranslationTextComponent("You are not "+en),Util.DUMMY_UUID); }
  11. I am a bigginer at Java and do not know much about reflection but I know it allows to get private var, methods, annotations and so
  12. I ve seen an example of it but i dont understand how i can apply this to my problem. Do I need to call createmenu from new class in networkhooks.opengui method?
  13. I dont quite understand what you mean by this. I created a new class. NetworkHooks.openGui((ServerPlayerEntity) playerEntity,new MyModContainer(0,new anonymousInnerClass() { },playerEntity.inventory)); public class anonymousInnerClass implements INamedContainerProvider { @Override public ITextComponent getDisplayName() { return new StringTextComponent("Name"); } @Nullable @Override public Container createMenu(int id, PlayerInventory playerInventory, PlayerEntity playerEntity) { return new MyModContainer(id,playerInventory); } }
  14. But where i can get the instance Map<Structure<?>, StructureFeature<?, ?>> STR = ObfuscationReflectionHelper.getPrivateValue(FlatGenerationSettings.class,instance,"STRUCTURES");
  15. How i can put my structures in to FlatGenerationSettings.STRUCTURES. The structures var is final so i cant put mine like that FlatGenerationSettings.STRUCTURES.put(MyStructure.RUN_DOWN_HOUSE.get(), CONFIGURED_RUN_DOWN_HOUSE);
  16. What should implement INamedContainerProvider
  17. So what needs to be implemented? My Entity?
  18. Is it ok that i am saving a player uuid as a string in datamanager private static final DataParameter<String> OWNER = EntityDataManager.createKey(MyEntity.class, DataSerializers.STRING); @OnlyIn(Dist.CLIENT) public UUID getOwner() { return UUID.fromString(this.dataManager.get(OWNER)); } public void setOwner(UUID name) { this.dataManager.set(OWNER ,name.toString()); }
  19. where i can get uuid. from player entity? Should my entity implement it?
  20. i am trying to show my gui by clicking on my entity public ActionResultType func_230254_b_(PlayerEntity playerEntity, Hand hand) { if (!this.world.isRemote) { String en = getOwner(); String pl = playerEntity.getScoreboardName(); if(en.equals(pl)) { NetworkHooks.openGui((ServerPlayerEntity) playerEntity,new MyModContainer(0,playerEntity.inventory)); } else playerEntity.sendMessage(new TranslationTextComponent("You are not "+en),Util.DUMMY_UUID); } return ActionResultType.func_233537_a_(this.world.isRemote); }
  21. like this? NetworkHooks.openGui((ServerPlayerEntity) playerEntity,new MyModContainer(0,playerEntity.inventory));

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.