Jump to content

kaydogz

Members
  • Posts

    106
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by kaydogz

  1. 33 minutes ago, Viperdream said:

    I've been trying to create my own capability. However, when I try to write the storage class I'm getting an error.

    Whenever I use the writeNBT funciton and try to write my own float value to the FloatNBT object, it gives the error that FloatNBT has private access.

    I understand that this prevents me from writing my own value on the FloatNBT, but I haven't found a way around it.

     

    I've checked various tutorials and other people's code (that's also from 1.15.2). Using "FloatNBT.valueOf(instance.getPower());" doesn't work either (yet I've seen it working in other mods), since it can't resolve the symbol.

    This is my instance class:

    
    package com.github.viperdream.vnecro.capability.instances;
    
    import com.github.viperdream.vnecro.capability.interfaces.IRunicPower;
    import net.minecraft.nbt.FloatNBT;
    import net.minecraft.nbt.INBT;
    import net.minecraft.util.Direction;
    import net.minecraftforge.common.capabilities.Capability;
    
    import javax.annotation.Nullable;
    
    public class RunicPower implements IRunicPower {
        private float rp = 0.0F;
    
        public void consume(float points) {
            this.rp -= points;
            if(this.rp < 0.0F) this.rp = 0.0F;
        }
    
        public void fill(float points) {
            this.rp += points;
        }
    
        public void set(float points) {
            this.rp = points;
        }
    
        public float getPower() {
            return this.rp;
        }
    
        public static class Storage implements Capability.IStorage<IRunicPower>
        {
    
            @Nullable
            @Override
            public INBT writeNBT(Capability<IRunicPower> capability, IRunicPower instance, Direction side) {
                return new FloatNBT.valueOf(instance.getPower());
            }
    
            @Override
            public void readNBT(Capability<IRunicPower> capability, IRunicPower instance, Direction side, INBT nbt) {
                instance.set(((FloatNBT) nbt).getInt());
            }
        }
    }

     

    Could someone please point me in the right direction? I have the feeling I'm missing something obvious, but I can't see it at the moment.

     

    Thanks in advance!

    You don't need to have the 'new' in front of the FloatNBT#valueOf. The method is already creating one.

    Also, you want a float, not an int so use FloatNBT#getFloat instead of FloatNBT#getInt.

  2. I'm pretty sure your issue is arising from the fact that the entity is trying to change the dimension of the player while they are in the loading screen for the dimension.

    Btw, why do you have so many variables for your player? I'd remove the mastername and master entity variables and just keep the uuid. When you are using the player, just use World#getPlayerByUuid.

  3. For every loaded chunk in the Overworld, I want to load the chunk which corresponds with it in my dimension (same x and z). I currently have:

    @SubscribeEvent
    public static void chunkLoad(final ChunkEvent.Load event) {
    	if (event.getWorld() != null) if (!event.getWorld().isRemote()) {
    		ServerWorld world = (ServerWorld) event.getWorld();
    			
    		if (world.dimension.getType() == DBMDimensions.realm_of_the_ancients) {
    				
    			// Force Loads Corresponding Chunks in the Overworld
    			DBMChunkManager.getLoadedChunks(world).forEach((a, b) -> world.getServer().getWorld(DimensionType.OVERWORLD).forceChunk(b.getPosition().x, b.getPosition().z, true));
    		} else if (world.dimension.getType() == DimensionType.OVERWORLD && DBMDimensions.realm_of_the_ancients != null) {
    				
    			// Force Loads Corresponding Chunks in the Realm of the Ancients
    			DBMChunkManager.getLoadedChunks(world).forEach((a, b) -> world.getServer().getWorld(DBMDimensions.realm_of_the_ancients).forceChunk(b.getPosition().x, b.getPosition().z, true));
    		}
    	}
    }
    		
    @SubscribeEvent
    public static void chunkUnload(final ChunkEvent.Unload event) {
    	if (event.getWorld() != null) if (!event.getWorld().isRemote()) {
    		ServerWorld world = (ServerWorld) event.getWorld();
    			
    		if (world.dimension.getType() == DBMDimensions.realm_of_the_ancients) {
    				
    			// Force Unloads Corresponding Chunks in the Overworld
    			world.getServer().getWorld(DimensionType.OVERWORLD).forceChunk(event.getChunk().getPos().x, event.getChunk().getPos().z, false);
    		} else if (world.dimension.getType() == DimensionType.OVERWORLD && DBMDimensions.realm_of_the_ancients != null) {
    				
    			// Force Unloads Corresponding Chunks in the Realm of the Ancients
    			world.getServer().getWorld(DBMDimensions.realm_of_the_ancients).forceChunk(event.getChunk().getPos().x, event.getChunk().getPos().z, false);
    		}
    	}
    }

    And here is the class I made to get the loaded chunks:

    public class DBMChunkManager {
    
    	private static final Field LOADED_CHUNKS_FIELD = ObfuscationReflectionHelper.findField(ChunkManager.class, "immutableLoadedChunks");
    	
    	static {
    		LOADED_CHUNKS_FIELD.setAccessible(true);
    	}
    
    	@SuppressWarnings("unchecked") @Nullable
    	public static Long2ObjectLinkedOpenHashMap<ChunkHolder> getLoadedChunks(ServerWorld world) {
    		try {
    			return (Long2ObjectLinkedOpenHashMap<ChunkHolder>) LOADED_CHUNKS_FIELD.get(world.getChunkProvider().chunkManager);
    			
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		return null;
    	}
    }

     

    However, any time I try to create a new world, the game gets stuck at 0%.
    The last console message to show up is:

    [01May2020 23:18:46.645] [Server thread/INFO] [net.minecraftforge.common.DimensionManager/DIMS]: Registered dimension daboismod:the_realm_of_the_ancients of type daboismod:the_realm_of_the_ancients and id 3

    The game doesn't crash or suspend, it just does not do anything from this point onward. Any help is greatly appreciated.

  4. 1 minute ago, PixxiBunny said:

    Alright, here's what I got. Still some errors though, any idea what's wrong?
     

    
        // Food
        public static final RegistryObject<Item> COTTON_STEAK_RAW = ITEMS.register("cotton_steak_raw", ItemBase::new);
        public static final RegistryObject<Item> COTTON_STEAK = ITEMS.register("cotton_steak", () -> return new Item(new Item.Properties().food(Foods.COTTON_STEAK)));
    
        public static class Foods {
            public static final Food COTTON_STEAK = (new Food.Builder()).hunger(8).saturation(12.8f).meat().build();
    
        }

     

    Sorry, my bad. I had a typo from before. Just remove the return

  5. 15 minutes ago, PixxiBunny said:

    It's saying cannot resolve symbol 'foodInstance'. Also, where would I place this code?

    
        // Food
        public static final RegistryObject<Item> COTTON_STEAK_RAW = ITEMS.register("cotton_steak_raw", ItemBase::new);
        public static final RegistryObject<Item> COTTON_STEAK = ITEMS.register("cotton_steak", ItemBase::new);
    
        public static class Foods {
            public static final Food COTTON_STEAK = (new Food.Builder()).hunger(8).saturation(12.8f).meat().build();
            
        }
            new Item(new Item.Properties().food(foodInstance))
    }

     

    foodInstance is what I put as a placeholder for the instance of your food, which is for you, Foods.COTTON_STEAK.

    You would put the line as such:
    ITEMS.register("itemregistryname", () -> new Item(new Item.Properties().food(foodInstance)));

    As I said before, please learn java before you start modding.
    Edit: And please remember to swap my placeholders for your values.

  6. 14 minutes ago, PixxiBunny said:

    How would I do this? I'm sorry I'm asking so much, I'm fairly new to this.

    new Item(new Item.Properties().food(foodInstance))

    PLEASE learn basic java before you start modding, so you won't have to ask questions like these.

  7. 13 minutes ago, PixxiBunny said:

    Here's what I got, still not letting me eat it:

    
        // Food
        public static final RegistryObject<Item> COTTON_STEAK_RAW = ITEMS.register("cotton_steak_raw", ItemBase::new);
        public static final RegistryObject<Item> COTTON_STEAK = ITEMS.register("cotton_steak", ItemBase::new);
    
        public static class Foods {
            public static final Food COTTON_STEAK = (new Food.Builder()).hunger(8).saturation(12.8f).meat().build();
        }

     

    It's not letting you eat it because you haven't applied the food to the item's Item.Properties

  8. 4 minutes ago, PixxiBunny said:

    I'm sorry, but how would I do this?

    new Food.Builder(....).build()

    then when instantiating your item, pass in your food instance:

    new Item.Properties().food(foodinstance)

  9. 16 minutes ago, PixxiBunny said:

    How would I do that exactly?

    You would create a new instance of java.util.Random then use random.nextInt() * (max - min) + min to get a random integer between min and max (inclusive, exclusive).

     

    Since you're new to modding and java, I strongly recommend taking a java course to learn about java.util.Random and more of the basics before you proceed. Modding Minecraft is not the best way of learning the language.

    • Like 1
  10. I want my dimension to stay loaded all the time, so I want to use keepLoaded. However, I don't know where to put it. Here is what I have currently: (this line is called in FMLCommonSetupEvent)

    		DimensionManager.keepLoaded(DimensionManager.registerDimension(DaBoisMod.modLocation("the_realm_of_the_ancients"), DBMDimensions.the_realm_of_the_ancients, new PacketBuffer(Unpooled.buffer(16)), false), true);

    However, it doesn't work, as the dimension unloads when I leave it. Am I putting keepLoaded in the wrong place? Thanks for any help.

  11. Thanks guys! I finally got it to work. I'm not exactly sure how I didn't know the LivingFallEvent existed... but here's the code for anyone that wants to see:

    @SubscribeEvent
    public static void playerTick(final TickEvent.PlayerTickEvent event) {
    	if (event.side == LogicalSide.SERVER && event.player.dimension == DBMDimension.getType(DBMDimensions.the_realm_of_the_ancients_dimension) && event.player.getPosition().getY() <= 0) {
    		DBMTeleporter.teleportPlayerTop(event.player);
    		if (!DaBoisMod.getCapabilityOf(event.player, FallingFromSkyProvider.FALLING_FROM_SKY_CAPABILITY).isFallingFromSky())
    			DaBoisMod.getCapabilityOf(event.player, FallingFromSkyProvider.FALLING_FROM_SKY_CAPABILITY).setFallingFromSky(true);
    	}
    }
    
    @SubscribeEvent
    public static void livingFall(final LivingFallEvent event) {
    	if (event.getEntity() instanceof PlayerEntity) {
    		PlayerEntity player = (PlayerEntity) event.getEntity();
    		if (DaBoisMod.getCapabilityOf(player, FallingFromSkyProvider.FALLING_FROM_SKY_CAPABILITY).isFallingFromSky()) {
    			event.setCanceled(true);
    			DaBoisMod.getCapabilityOf(player, FallingFromSkyProvider.FALLING_FROM_SKY_CAPABILITY).setFallingFromSky(false);
    		}
    	}
    }
  12. I made a dimension called the Realm of the Ancients, and when you fall into the abyss below, I want it to teleport you to the top of the Overworld, Aether-style. I made a capability called FallingFromSky which just stores a boolean that denotes if the player is falling from the dimension. Here is my code:

    @SubscribeEvent
    	public static void playerTick(final TickEvent.PlayerTickEvent event) {
    		if (event.player.dimension == DBMDimension.getType(DBMDimensions.the_realm_of_the_ancients_dimension) && event.player.getPosition().getY() <= 0) {
    			DBMTeleporter.teleportPlayerTop(event.player);
    			if (!DaBoisMod.getCapabilityOf(event.player, FallingFromSkyProvider.FALLING_FROM_SKY_CAPABILITY).isFallingFromSky()) DBMPacketHandler.sendToServer(new SSyncFallingFromSkyPacket(true));
    		}
    		if (event.side == LogicalSide.SERVER && DaBoisMod.getCapabilityOf(event.player, FallingFromSkyProvider.FALLING_FROM_SKY_CAPABILITY).isFallingFromSky()) {
    			if (!event.player.onGround) event.player.fallDistance = 0F;
    			else DBMPacketHandler.sendToServer(new SSyncFallingFromSkyPacket(false));
    		}
    	}

    The packets just set the falling from sky variable.

    When I fall into the void of the dimension, it successfully teleports me to the top of the Overworld and I fall to the ground and take no damage. However, when I open to LAN just to test how it would work on a server, I die when falling. I tried to debug by logging to the console the falling from sky variable every tick, and it shows that the value is true for only a second in the Overworld, after which it turns false. Any help is appreciated.

  13. 51 minutes ago, Scholler said:

    So KeyBinding is like keyBindings[0] = new KeyBinding("Blabla..", KeyValue, "blabla");
    It was working in 1.12 but there is no org.lwjgl.input.Keyboard to use in 1.15 forge

    No... create a static KeyBinding and instantiate it in FMLClientSetupEvent. In the same event, register it to the client using ClientRegistry::registerKeyBinding

×
×
  • Create New...

Important Information

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