Jump to content

[1.16.5] Problem with getting capabilities to work


TheDerpyParagon

Recommended Posts

I am making a mod that is based on the titan shifters from attack on titan, and I am trying to get capabilities to work in my mod, but my main class is failing me. (I think) My mod runs perfectly fine until I try to join a world, where it crashes with the error:

AL lib: (EE) alc_cleanup: 1 device not closed

And here is my main class:

package com.derpyzombie.titanshiftersmod;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.derpyzombie.titanshiftersmod.capabilities.ITitanShifters;
import com.derpyzombie.titanshiftersmod.capabilities.TitanShifters;
import com.derpyzombie.titanshiftersmod.capabilities.TitanShiftersProvider;
import com.derpyzombie.titanshiftersmod.capabilities.TitanShiftersStorage;
import com.derpyzombie.titanshiftersmod.common.events.PlayerSizeControl;
import com.derpyzombie.titanshiftersmod.core.init.ItemInit;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

// The value here should match an entry in the META-INF/mods.toml file
@Mod("titanshiftersmod")
@Mod.EventBusSubscriber(modid = TitanShiftersMod.MOD_ID, bus = Bus.FORGE)
public class TitanShiftersMod
{
    // Directly reference a log4j logger.
    private static final Logger LOGGER = LogManager.getLogger();
    public static final String MOD_ID = "titanshiftersmod";
    public static final String MOD_VERSION = "0.1";

    public TitanShiftersMod() {
    	IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
    	
    	ItemInit.ITEMS.register(bus);
    	MinecraftForge.EVENT_BUS.register(new PlayerSizeControl());
    
    	MinecraftForge.EVENT_BUS.register(this);
    	
    	FMLJavaModLoadingContext.get().getModEventBus().addListener(TitanShiftersMod::onCommonSetup);
    }
    
    @SubscribeEvent
    public static void onCommonSetup(FMLCommonSetupEvent event) {
    	CapabilityManager.INSTANCE.register(ITitanShifters.class, new TitanShiftersStorage(), TitanShifters::new);
    }
    
    @SubscribeEvent
    public static void onAttachCapabilities(AttachCapabilitiesEvent<Entity> event) {
    	if (event.getObject() instanceof PlayerEntity) {
    		event.addCapability(new ResourceLocation(MOD_ID, "titanshifters"), new TitanShiftersProvider());
    	}
    }
    
//    @SubscribeEvent
//    public void playerLogsIn(PlayerLoggedInEvent event) {
//    	PlayerEntity player = event.getPlayer();
//    	LazyOptional<ITitanShifters> titanshifter = player.getCapability(TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY);
//		ITitanShifters titan = titanshifter.orElse(new TitanShifters());
//		player.sendMessage(new StringTextComponent("Hello from DerpyZombie!"), new UUID(0, 0));
//    }
}

When I made the onCommonSetup event and the AttachCapabilities event and subscribed to them, my game started to crash when I joined a world. It could be something to do with any of my other capability classes, I think, so I will also provide those.

ITitanShifters:

package com.derpyzombie.titanshiftersmod.capabilities;

public interface ITitanShifters {

	Boolean getPureTitan();
	Boolean getTitanShifter();
	Boolean getFoundingTitan();
	Boolean getAttackTitan();
	Boolean getColossalTitan();
	Boolean getJawTitan();
	Boolean getWarHammerTitan();
	Boolean getArmoredTitan();
	Boolean getBeastTitan();
	Boolean getFemaleTitan();
	Boolean getCartTitan();
	
	void setPureTitan(Boolean PureTitan);
	void setTitanShifter(Boolean TitanShifter);
	void setFoundingTitan(Boolean FoundingTitan);
	void setAttackTitan(Boolean AttackTitan);
	void setColossalTitan(Boolean ColossalTitan);
	void setJawTitan(Boolean JawTitan);
	void setWarHammerTitan(Boolean WarHammerTitan);
	void setArmoredTitan(Boolean ArmoredTitan);
	void setBeastTitan(Boolean BeastTitan);
	void setFemaleTitan(Boolean FemaleTitan);
	void setCartTitan(Boolean CartTitan);
}

TitanShifters:

package com.derpyzombie.titanshiftersmod.capabilities;

public class TitanShifters implements ITitanShifters {

	private Boolean PureTitan;
	private Boolean TitanShifter;
	private Boolean FoundingTitan;
	private Boolean AttackTitan;
	private Boolean ColossalTitan;
	private Boolean JawTitan;
	private Boolean WarHammerTitan;
	private Boolean ArmoredTitan;
	private Boolean BeastTitan;
	private Boolean FemaleTitan;
	private Boolean CartTitan;
	
	public TitanShifters() {
		this.TitanShifter = true;
		this.FoundingTitan = false;
		this.AttackTitan = false;
		this.ColossalTitan = false;
		this.JawTitan = false;
		this.WarHammerTitan = false;
		this.ArmoredTitan = false;
		this.BeastTitan = false;
		this.FemaleTitan = false;
		this.CartTitan = false;
	}

	@Override
	public Boolean getPureTitan() {
		return this.PureTitan;
	}
	
	@Override
	public Boolean getTitanShifter() {
		return this.TitanShifter;
	}

	@Override
	public Boolean getFoundingTitan() {
		return this.FoundingTitan;
	}

	@Override
	public Boolean getAttackTitan() {
		return this.AttackTitan;
	}

	@Override
	public Boolean getColossalTitan() {
		return this.ColossalTitan;
	}

	@Override
	public Boolean getJawTitan() {
		return this.JawTitan;
	}

	@Override
	public Boolean getWarHammerTitan() {
		return this.WarHammerTitan;
	}

	@Override
	public Boolean getArmoredTitan() {
		return this.ArmoredTitan;
	}

	@Override
	public Boolean getBeastTitan() {
		return this.BeastTitan;
	}

	@Override
	public Boolean getFemaleTitan() {
		return this.FemaleTitan;
	}

	@Override
	public Boolean getCartTitan() {
		return this.CartTitan;
	}

	@Override
	public void setPureTitan(Boolean PureTitan) {
		this.PureTitan = PureTitan;
	}
	
	@Override
	public void setTitanShifter(Boolean TitanShifter) {
		this.TitanShifter = TitanShifter;
	}

	@Override
	public void setFoundingTitan(Boolean FoundingTitan) {
		this.FoundingTitan = FoundingTitan;
	}

	@Override
	public void setAttackTitan(Boolean AttackTitan) {
		this.AttackTitan = AttackTitan;
	}

	@Override
	public void setColossalTitan(Boolean ColossalTitan) {
		this.ColossalTitan = ColossalTitan;
	}

	@Override
	public void setJawTitan(Boolean JawTitan) {
		this.JawTitan = JawTitan;
	}

	@Override
	public void setWarHammerTitan(Boolean WarHammerTitan) {
		this.WarHammerTitan = WarHammerTitan;
	}

	@Override
	public void setArmoredTitan(Boolean ArmoredTitan) {
		this.ArmoredTitan = ArmoredTitan;
	}

	@Override
	public void setBeastTitan(Boolean BeastTitan) {
		this.BeastTitan = BeastTitan;
	}

	@Override
	public void setFemaleTitan(Boolean FemaleTitan) {
		this.FemaleTitan = FemaleTitan;
	}

	@Override
	public void setCartTitan(Boolean CartTitan) {
		this.CartTitan = CartTitan;
	}
}

TitanShiftersProvider:

package com.derpyzombie.titanshiftersmod.capabilities;

import net.minecraft.nbt.INBT;
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import net.minecraftforge.common.util.LazyOptional;

public class TitanShiftersProvider implements ICapabilitySerializable<INBT> {

	@CapabilityInject(ITitanShifters.class)
	public static final Capability<ITitanShifters> TITAN_SHIFTERS_CAPABILITY = null;

	private LazyOptional<ITitanShifters> instance = LazyOptional.of(TITAN_SHIFTERS_CAPABILITY::getDefaultInstance);
	
	public Boolean hasCapability(Capability<?> capability, Direction side) {
		return capability == TITAN_SHIFTERS_CAPABILITY;
	}
	
	@Override
	public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
		return cap == TITAN_SHIFTERS_CAPABILITY ? instance.cast() : LazyOptional.empty();
	}

	@Override
	public INBT serializeNBT() {
		//@formatter:off
		return TITAN_SHIFTERS_CAPABILITY.getStorage().writeNBT(TITAN_SHIFTERS_CAPABILITY,
				instance.orElseThrow(() -> new IllegalArgumentException("LazyOptional must not be empty!")), null);
		//@formatter:on
	}

	@Override
	public void deserializeNBT(INBT nbt) {
		//@formatter:off
		TITAN_SHIFTERS_CAPABILITY.getStorage().readNBT(TITAN_SHIFTERS_CAPABILITY,
				instance.orElseThrow(() -> new IllegalArgumentException("LazyOptional must not be empty!")), null, nbt);
		//@formatter:on
	}

}

TitanShiftersStorage:

package com.derpyzombie.titanshiftersmod.capabilities;

import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.Capability.IStorage;

public class TitanShiftersStorage implements IStorage<ITitanShifters> {

	@Override
	public INBT writeNBT(Capability<ITitanShifters> capability, ITitanShifters instance, Direction side) {
		CompoundNBT tag = new CompoundNBT();
		tag.putBoolean("TitanShifter", instance.getTitanShifter());
		tag.putBoolean("FoundingTitan", instance.getFoundingTitan());
		tag.putBoolean("AttackTitan", instance.getAttackTitan());
		tag.putBoolean("ColossalTitan", instance.getColossalTitan());
		tag.putBoolean("JawTitan", instance.getJawTitan());
		tag.putBoolean("WarHammerTitan", instance.getWarHammerTitan());
		tag.putBoolean("ArmoredTitan", instance.getArmoredTitan());
		tag.putBoolean("BeastTitan", instance.getBeastTitan());
		tag.putBoolean("FemaleTitan", instance.getFemaleTitan());
		tag.putBoolean("CartTitan", instance.getCartTitan());
		tag.putBoolean("PureTitan", instance.getPureTitan());
		return tag;
	}

	@Override
	public void readNBT(Capability<ITitanShifters> capability, ITitanShifters instance, Direction side, INBT nbt) {
		CompoundNBT tag = (CompoundNBT) nbt;
		instance.setTitanShifter(tag.getBoolean("TitanShifter"));
		instance.setFoundingTitan(tag.getBoolean("FoundingTitan"));
		instance.setAttackTitan(tag.getBoolean("AttackTitan"));
		instance.setColossalTitan(tag.getBoolean("ColossalTitan"));
		instance.setJawTitan(tag.getBoolean("JawTitan"));
		instance.setWarHammerTitan(tag.getBoolean("WarHammerTitan"));
		instance.setArmoredTitan(tag.getBoolean("ArmoredTitan"));
		instance.setBeastTitan(tag.getBoolean("BeastTitan"));
		instance.setFemaleTitan(tag.getBoolean("FemaleTitan"));
		instance.setCartTitan(tag.getBoolean("CartTitan"));
		instance.setPureTitan(tag.getBoolean("PureTitan"));
	}

}

 

Link to comment
Share on other sites

Whoops, my bad.

Here's the error:

[15:57:57] [Netty Local Client IO #0/INFO] [ne.mi.fm.ne.NetworkHooks/]: Connected to a modded server.
[15:57:57] [Server thread/ERROR] [ne.mi.ev.EventBus/EVENTBUS]: Exception caught during firing event: Duplicate Capability Key: titanshiftersmod:titanshifters com.derpyzombie.titanshiftersmod.capabilities.TitanShiftersProvider@471e4c80
	Index: 2
	Listeners:
		0: NORMAL
		1: ASM: class com.derpyzombie.titanshiftersmod.capabilities.CapabilityAttacher onAttachCapabilities(Lnet/minecraftforge/event/AttachCapabilitiesEvent;)V
		2: ASM: class com.derpyzombie.titanshiftersmod.TitanShiftersMod onAttachCapabilities(Lnet/minecraftforge/event/AttachCapabilitiesEvent;)V
java.lang.IllegalStateException: Duplicate Capability Key: titanshiftersmod:titanshifters com.derpyzombie.titanshiftersmod.capabilities.TitanShiftersProvider@471e4c80
	at net.minecraftforge.event.AttachCapabilitiesEvent.addCapability(AttachCapabilitiesEvent.java:71)
	at com.derpyzombie.titanshiftersmod.TitanShiftersMod.onAttachCapabilities(TitanShiftersMod.java:55)
	at net.minecraftforge.eventbus.ASMEventHandler_10_TitanShiftersMod_onAttachCapabilities_AttachCapabilitiesEvent.invoke(.dynamic)
	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85)
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302)
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283)
	at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:597)
	at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:591)
	at net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:48)
	at net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:44)
	at net.minecraft.entity.Entity.<init>(Entity.java:221)
	at net.minecraft.entity.LivingEntity.<init>(LivingEntity.java:205)
	at net.minecraft.entity.player.PlayerEntity.<init>(PlayerEntity.java:159)
	at net.minecraft.entity.player.ServerPlayerEntity.<init>(ServerPlayerEntity.java:179)
	at net.minecraft.server.management.PlayerList.getPlayerForLogin(PlayerList.java:406)
	at net.minecraft.network.login.ServerLoginNetHandler.handleAcceptedLogin(ServerLoginNetHandler.java:118)
	at net.minecraft.network.login.ServerLoginNetHandler.tick(ServerLoginNetHandler.java:65)
	at net.minecraft.network.NetworkManager.tick(NetworkManager.java:222)
	at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:134)
	at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:865)
	at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:787)
	at net.minecraft.server.integrated.IntegratedServer.tickServer(IntegratedServer.java:78)
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:642)
	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:232)
	at java.lang.Thread.run(Unknown Source)

 

Link to comment
Share on other sites

Ah, thanks.

the game throws another error at me after this, though.

[16:25:54] [Server thread/INFO] [minecraft/MinecraftServer]: Dev joined the game
[16:25:55] [Render thread/ERROR] [ne.mi.ev.EventBus/EVENTBUS]: Exception caught during firing event: null
	Index: 1
	Listeners:
		0: NORMAL
		1: ASM: class com.derpyzombie.titanshiftersmod.common.events.PlayerSizeControl crouching(Lnet/minecraftforge/event/entity/player/PlayerEvent;)V
java.lang.NullPointerException
	at com.derpyzombie.titanshiftersmod.common.events.PlayerSizeControl.crouching(PlayerSizeControl.java:51)
	at net.minecraftforge.eventbus.ASMEventHandler_6_PlayerSizeControl_crouching_PlayerEvent.invoke(.dynamic)
	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85)
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302)
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283)
	at net.minecraftforge.event.ForgeEventFactory.onItemTooltip(ForgeEventFactory.java:289)
	at net.minecraft.item.ItemStack.getTooltipLines(ItemStack.java:702)
	at net.minecraft.client.Minecraft.lambda$null$11(Minecraft.java:665)
	at java.util.stream.ReferencePipeline$7$1.accept(Unknown Source)
	at java.util.Collections$2.tryAdvance(Unknown Source)
	at java.util.Collections$2.forEachRemaining(Unknown Source)
	at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(Unknown Source)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source)
	at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
	at java.util.stream.ReferencePipeline.forEach(Unknown Source)
	at net.minecraft.client.util.SearchTree.index(SearchTree.java:35)
	at net.minecraft.client.util.SearchTreeReloadable.add(SearchTreeReloadable.java:46)
	at com.google.common.collect.ImmutableList.forEach(ImmutableList.java:408)
	at net.minecraft.client.network.play.ClientPlayNetHandler.handleUpdateRecipes(ClientPlayNetHandler.java:1312)
	at net.minecraft.network.play.server.SUpdateRecipesPacket.handle(SUpdateRecipesPacket.java:27)
	at net.minecraft.network.play.server.SUpdateRecipesPacket.handle(SUpdateRecipesPacket.java:16)
	at net.minecraft.network.PacketThreadUtil.lambda$ensureRunningOnSameThread$0(PacketThreadUtil.java:19)
	at net.minecraft.util.concurrent.ThreadTaskExecutor.doRunTask(ThreadTaskExecutor.java:136)
	at net.minecraft.util.concurrent.RecursiveEventLoop.doRunTask(RecursiveEventLoop.java:22)
	at net.minecraft.util.concurrent.ThreadTaskExecutor.pollTask(ThreadTaskExecutor.java:109)
	at net.minecraft.util.concurrent.ThreadTaskExecutor.runAllTasks(ThreadTaskExecutor.java:97)
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:947)
	at net.minecraft.client.Minecraft.run(Minecraft.java:607)
	at net.minecraft.client.main.Main.main(Main.java:184)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52)
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37)
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54)
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72)
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:82)
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:66)
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:108)

This error seems really weird to me because when I get this error, I am loading into the world and I kind of spawn in. (I can see the middle cursor but the world around me hasn't loaded yet.) However, other times I can load in perfectly fine but the game crashes after a few seconds of playing. About 15 seconds into playing. Here's the modified main class just in case someone wants it:

package com.derpyzombie.titanshiftersmod;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.derpyzombie.titanshiftersmod.capabilities.ITitanShifters;
import com.derpyzombie.titanshiftersmod.capabilities.TitanShifters;
import com.derpyzombie.titanshiftersmod.capabilities.TitanShiftersProvider;
import com.derpyzombie.titanshiftersmod.capabilities.TitanShiftersStorage;
import com.derpyzombie.titanshiftersmod.common.events.PlayerSizeControl;
import com.derpyzombie.titanshiftersmod.core.init.ItemInit;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

// The value here should match an entry in the META-INF/mods.toml file
@Mod("titanshiftersmod")
@Mod.EventBusSubscriber(modid = TitanShiftersMod.MOD_ID, bus = Bus.FORGE)
public class TitanShiftersMod
{
    // Directly reference a log4j logger.
    private static final Logger LOGGER = LogManager.getLogger();
    public static final String MOD_ID = "titanshiftersmod";
    public static final String MOD_VERSION = "0.1";
    
    public static final ResourceLocation resourceLocation = new ResourceLocation(MOD_ID, "puretitan");

    public TitanShiftersMod() {
    	IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
    	
    	ItemInit.ITEMS.register(bus);
    	MinecraftForge.EVENT_BUS.register(new PlayerSizeControl());
    
    	MinecraftForge.EVENT_BUS.register(this);
    	
    	bus.addListener(TitanShiftersMod::onCommonSetup);
    }
    
    @SubscribeEvent
    public static void onCommonSetup(FMLCommonSetupEvent event) {
    	CapabilityManager.INSTANCE.register(ITitanShifters.class, new TitanShiftersStorage(), TitanShifters::new);
    }
    
     @SubscribeEvent
    public static void onAttachCapabilities(AttachCapabilitiesEvent<Entity> event) {
    	if (event.getObject() instanceof PlayerEntity) {
    		event.addCapability(resourceLocation, new TitanShiftersProvider());
    	}
    }
    
//    @SubscribeEvent
//    public void playerLogsIn(PlayerLoggedInEvent event) {
//    	PlayerEntity player = event.getPlayer();
//    	LazyOptional<ITitanShifters> titanshifter = player.getCapability(TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY);
//		ITitanShifters titan = titanshifter.orElse(new TitanShifters());
//		player.sendMessage(new StringTextComponent("Hello from DerpyZombie!"), new UUID(0, 0));
//    }
}

 

Link to comment
Share on other sites

age com.derpyzombie.titanshiftersmod.common.events;

import com.derpyzombie.titanshiftersmod.TitanShiftersMod;
import com.derpyzombie.titanshiftersmod.common.items.TitanSpinalFluid;

import net.minecraft.entity.Pose;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;

@EventBusSubscriber(modid = TitanShiftersMod.MOD_ID, bus = Bus.FORGE)
public class PlayerSizeControl {
	
    private static float sizemultiplier = 1f;
    private static float stepUp = 0.5f;
   
    public static void changeSize(float size) {
    		sizemultiplier = size;
    }
    
    @SubscribeEvent
    public void onPlayerRenderPre(RenderPlayerEvent.Pre event){
    	
        event.getMatrixStack().pushPose();
        event.getMatrixStack().scale(sizemultiplier, sizemultiplier, sizemultiplier);
    }

    @SubscribeEvent
    public void onPlayerRenderPost(RenderPlayerEvent.Post event){
    	
        	event.getMatrixStack().popPose();
    }
    
    @SubscribeEvent
    public static void changeHeight(EntityEvent.Size event) {
    	
    	if (event.getEntity() instanceof PlayerEntity) {
    		
    			event.setNewEyeHeight(sizemultiplier * 1.6f);
    			event.setNewSize(event.getNewSize().scale(sizemultiplier));
    			event.getEntity().maxUpStep = stepUp;
    	}
    }
    
    @SubscribeEvent
    public static void crouching(PlayerEvent player) {
    		player.getEntity().setPose(Pose.CROUCHING); **********
    		player.getEntity().setPose(Pose.STANDING);
    }
}

The line with the stars next to it is line 51.

I see I have made a mistake here, because this event will basically constantly crouch then stand back up. This event is only supposed to happen when a certain condition is met. I'm not sure why this would crash the game, though.

Link to comment
Share on other sites

On 11/25/2021 at 1:33 AM, TheDerpyParagon said:
java.lang.NullPointerException
	at com.derpyzombie.titanshiftersmod.common.events.PlayerSizeControl.crouching(PlayerSizeControl.java:51)

this is the error, but your code looks okay, not sure why it will throw there a NullPointerException, can you post a git repo

Link to comment
Share on other sites

Even though I have quite limited experience, why did you split your item registry into a package called "core"? that is confusing. It should be located where the rest of the item classes are, in common. Also, your PlayerSize class is in common. But the graphics transformations are client-sided. Let me explain the structure I use:

Common package, for anything that is needed on both the client and server
	items
		Item classes
		Item registry class
	blocks
		Block classes
		Block registry class
	network
		Packet classes
		Network manager class
    	

Client package, for anything that can only run on the client
	gui
		overlay
			Overlay classes
			Overlay renderer
	
and so on.

You need to send a packet to other clients (tracking entities) when doing the transformation. See the forge documentation on Simple Channel.

Link to comment
Share on other sites

Also, your resourcelocations are broken. You cannot use capital letters in resource locations. For example, your 

LjaWAr8.png

caused forge to not load the mod. Replace it with puretitan in all occurences. 

Your NBT is failing to save because you did not assign a default value to the PureTitan boolean in the constructor, so the boolean is null. Coming from a C# background, I actually blame java for allowing booleans to be nullable. 

Link to comment
Share on other sites

5 hours ago, matthew123 said:

Even though I have quite limited experience, why did you split your item registry into a package called "core"? that is confusing. It should be located where the rest of the item classes are, in common. Also, your PlayerSize class is in common. But the graphics transformations are client-sided. Let me explain the structure I use:

it doesn't matter at all, it is his decision how he structures his project (Edit: there is no predefined package structure from Forge, however, it is recommended to use a package structure similar to minecraft or forge)

5 hours ago, matthew123 said:

Also, your repo's structure is messed up. You missed the gradle files. 

in addition to matthew123, use a Git Client to upload your project

5 hours ago, matthew123 said:

Your NBT is failing to save because you did not assign a default value to the PureTitan boolean in the constructor, so the boolean is null. Coming from a C# background, I actually blame java for allowing booleans to be nullable. 

the reason for this is that you usually use primitive data types, like boolean, int, double and not their classes (Boolean, Integer, Double)

5 hours ago, matthew123 said:

the mod looks like it's working now. But do remember to fix the structure, and use packets for synchronization.

update your git repo and tell us how the reproduce the error

Edited by Luis_ST
Link to comment
Share on other sites

21 hours ago, matthew123 said:

Even though I have quite limited experience, why did you split your item registry into a package called "core"? that is confusing. It should be located where the rest of the item classes are, in common. Also, your PlayerSize class is in common. But the graphics transformations are client-sided. Let me explain the structure I use:

Common package, for anything that is needed on both the client and server
	items
		Item classes
		Item registry class
	blocks
		Block classes
		Block registry class
	network
		Packet classes
		Network manager class
    	

Client package, for anything that can only run on the client
	gui
		overlay
			Overlay classes
			Overlay renderer
	
and so on.

You need to send a packet to other clients (tracking entities) when doing the transformation. See the forge documentation on Simple Channel.

The reason I have structured my mod like this is because when I first got into modding, which wasn't too long ago, I watched a tutorial to get started, and the person in the tutorial structured their mod like that, so that's just what I've been doing. What you said does make more sense to me, though, so I'll change up my structure to make more sense. As for the client package, I'm going to keep my PlayerSizeControl class in common because yes, there are client-sided things in the class like the renderPlayerEvent events, but there are other things that are non-client-sided like EntityEvent.size. I'm pretty sure client-sided means just rendering, correct?

 

21 hours ago, matthew123 said:

Also, your resourcelocations are broken. You cannot use capital letters in resource locations. For example, your 

LjaWAr8.png

caused forge to not load the mod. Replace it with puretitan in all occurences. 

Your NBT is failing to save because you did not assign a default value to the PureTitan boolean in the constructor, so the boolean is null. Coming from a C# background, I actually blame java for allowing booleans to be nullable. 

Thanks, it would've taken me a long time to notice that I didn't assign any value to the pureTitan Boolean in my constructor. I'll also change my resource location to have no capitals.

 

Link to comment
Share on other sites

2 hours ago, TheDerpyParagon said:

The reason I have structured my mod like this is because when I first got into modding, which wasn't too long ago, I watched a tutorial to get started, and the person in the tutorial structured their mod like that, so that's just what I've been doing. What you said does make more sense to me, though, so I'll change up my structure to make more sense. As for the client package, I'm going to keep my PlayerSizeControl class in common because yes, there are client-sided things in the class like the renderPlayerEvent events, but there are other things that are non-client-sided like EntityEvent.size. I'm pretty sure client-sided means just rendering, correct?

 

Thanks, it would've taken me a long time to notice that I didn't assign any value to the pureTitan Boolean in my constructor. I'll also change my resource location to have no capitals.

 

You should change your types to "boolean", so you can't get problems like these in the future.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello! I have recently purchased a new computer and cannot download Optifine or Forge. The issue I am having is that the Java program 'javaw.exe' does not seem to open .jar files for me. As far as I can tell, I cannot open .jar files at all. The trouble-shooting I have tried so far is that I have un-downloaded and re-downloaded Java and that has not fixed it. I have followed the pathway to 'open with->choose another app->choose an app on your pc->Program Files (x86)->Java->jre-1.8->bin. and from inside bin I have tried opening these programs with each and every java application in there assuming I may have been wrong about which one I need to use. Still no luck. From there I checked to make sure that Java was allowed through my firewall and have seen no instances of any application with Java in the name anywhere in the list of apps to let through fire wall. I'm unsure of what to try next, so I would absolutely love help figuring out why my computer is not letting me open .jar files. Specifically these ones that I know are meant to open as installers. Any ideas are appreciated. Thanks in advance!
    • Thanks again for your anwsers, I tested without practical_plushies_mobs, practical_plushies_animals and dark-waters and now red forge loading screen appears however few seconds later it crashed again.  How I could put my file codes in my minecraft folder?
    • I have a modded mob that when I try to spawn it, it won't spawn and a crash happens (doesn't crash whole game though) and it says "Duplicate id value for 16!" and points to the mob's defineSynchedData method. Anyone know what's going on? Here's the method it was pointing to: @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(MY_BOOLEAN_DATA, false); }  
    • Click Here -- Official Website -- Order Now ➡️● For Order Official Website - https://sale365day.com/get-restore-cbd-gummies ➡️● Item Name: — Restore CBD Gummies ➡️● Ingredients: — All Natural ➡️● Incidental Effects: — NA ➡️● Accessibility: — Online ✅HUGE DISCOUNT ! HURRY UP! ORDER NOW!✅ ✅HUGE DISCOUNT ! HURRY UP! ORDER NOW!✅ ✅HUGE DISCOUNT ! HURRY UP! ORDER NOW!✅   Restore CBD Gummies is a strong contender for the top gummy of the year. Due to its strong concentration of CBD and purity, you will achieve excellent results while using it if you stick with this solution. Most people who suffer from constant pain, anxiety, depression, and insomnia are currently solving these problems, and you can be the next one. All you need to do is give Restore CBD Gummies a chance and let this fantastic product change your life. Visit the official website to order your Restore CBD Gummies today! After reading Restore CBD Gummies reviews, we now know that knee replacement surgeries are not the only option to treat knee pain, inflammation, joint discomfort, and stiffness. These CBD gummies can heal your joints and provide you relief from pain and stress so that you can lead a happy life. Prosper Wellness Restore CBD Gummies can improve joint mobility and improve knee health so that you can remain healthy. Exclusive Details: *Restore CBD Gummies* Read More Details on Official Website #USA! https://www.facebook.com/claritox.pro.unitedstates https://www.facebook.com/illudermaUCAAU https://www.facebook.com/awakenxtusa https://groups.google.com/a/chromium.org/g/chromium-reviews/c/8NMUVKgd-FA https://groups.google.com/g/microsoft.public.project/c/0UZQQKOZF58 https://groups.google.com/g/comp.editors/c/r_BcRRrvGhs https://medium.com/@illuderma/illuderma-reviews-fda-approved-breakthrough-or-clever-skincare-scam-36088ae82c3e https://medium.com/@claritoxpros/claritox-pro-reviews-legitimate-or-deceptive-dr-warns-of-potential-dangers-d5ff3867b34d https://medium.com/@thedetoxall17/detoxall-17-reviews-scam-alert-or-legit-detox-solution-customer-report-inside-1fd4c6920c9e https://groups.google.com/a/chromium.org/g/chromium-reviews/c/RONgLAl6vwM https://groups.google.com/g/microsoft.public.project/c/TgtOMRFt6nQ https://groups.google.com/g/comp.editors/c/fUfg0L2YfzU https://crediblehealths.blogspot.com/2023/12/revitalize-with-restore-cbd-gummies.html https://community.weddingwire.in/forum/restore-cbd-gummies-uncovered-fda-approved-breakthrough-or-deceptive-wellness-scam--t206896 https://restorecbdgummies.bandcamp.com/album/restore-cbd-gummies-uncovered-fda-approved https://my-restore-cb.clubeo.com/page/restore-cbd-gummies-reviews-customer-alert-drs-warning-genuine-or-wellness-hoax.html https://my-restore-cb.clubeo.com/page/restore-cbd-gummies-reviews-scam-alert-or-legit-relief-solution-customer-report-inside.html https://medium.com/@restorecbdgum/restore-cbd-gummies-reviews-warning-2023-update-real-or-a-powerful-relief-hoax-caution-350b61472a3f https://devfolio.co/@restorecbdgum https://restore-cbd-gummies-9.jimdosite.com/ https://devfolio.co/project/new/restore-cbd-gummies-reviews-scam-or-legit-custo-7bd6 https://groups.google.com/a/chromium.org/g/chromium-reviews/c/R0enUCvfs8s https://groups.google.com/g/microsoft.public.project/c/miJma2yOMDQ https://groups.google.com/g/comp.os.vms/c/S_HG94aaKFo https://groups.google.com/g/mozilla.dev.platform/c/qb6WpMUYLu0 https://hellobiz.in/restore-cbd-gummies-reviews-warning-2023-update-genuine-wellness-or-another-hoax-caution-211948390 https://pdfhost.io/v/ir5l.cseV_Restore_CBD_Gummies_Reviews_WARNING_2023_Update_Genuine_Wellness_or_Another_Hoax_Caution https://odoe.powerappsportals.us/en-US/forums/general-discussion/7c8b3f62-6d96-ee11-a81c-001dd8066f2b https://gamma.app/public/Restore-CBD-Gummies-ssh57nprs2l6xgq https://restorecbdgummies.quora.com/ https://www.facebook.com/RestoreCBDGummiesUS https://groups.google.com/g/restorecbdgum/c/9KHVNp3oy3E https://sites.google.com/view/restorecbdgummiesreviewsfdaapp/home https://experiment.com/projects/pjyhtzvpcvllopsglcph/methods https://lookerstudio.google.com/reporting/e5e9f52d-ae52-4c84-96c6-96b97932215f/page/XtkkD https://restore-cbd-gummies-reviews-is-it-a-sca.webflow.io/ https://colab.research.google.com/drive/1xZoc6E2H-jliBSZRVl0vnVqrkc3ix4YU https://soundcloud.com/restore-cbd-gummies-821066674/restore-cbd-gummies https://www.eventcreate.com/e/restore-cbd-gummies-reviews https://restorecbdgummies.godaddysites.com/ https://sketchfab.com/3d-models/restore-cbd-gummies-reviews-fda-approved-7cfe1fb8b003481c81689dd9489d2812 https://www.scoop.it/topic/restore-cbd-gummies-by-restore-cbd-gummies-9 https://events.humanitix.com/restore-cbd-gummies https://communityforums.atmeta.com/t5/General-Development/Restore-CBD-Gummies/m-p/1113602
    • Click Here -- Official Website -- Order Now ➡️● For Order Official Website - https://sale365day.com/get-restore-cbd-gummies ➡️● Item Name: — Restore CBD Gummies ➡️● Ingredients: — All Natural ➡️● Incidental Effects: — NA ➡️● Accessibility: — Online ✅HUGE DISCOUNT ! HURRY UP! ORDER NOW!✅ ✅HUGE DISCOUNT ! HURRY UP! ORDER NOW!✅ ✅HUGE DISCOUNT ! HURRY UP! ORDER NOW!✅   Restore CBD Gummies is a strong contender for the top gummy of the year. Due to its strong concentration of CBD and purity, you will achieve excellent results while using it if you stick with this solution. Most people who suffer from constant pain, anxiety, depression, and insomnia are currently solving these problems, and you can be the next one. All you need to do is give Restore CBD Gummies a chance and let this fantastic product change your life. Visit the official website to order your Restore CBD Gummies today! After reading Restore CBD Gummies reviews, we now know that knee replacement surgeries are not the only option to treat knee pain, inflammation, joint discomfort, and stiffness. These CBD gummies can heal your joints and provide you relief from pain and stress so that you can lead a happy life. Prosper Wellness Restore CBD Gummies can improve joint mobility and improve knee health so that you can remain healthy. Exclusive Details: *Restore CBD Gummies* Read More Details on Official Website #USA! https://www.facebook.com/claritox.pro.unitedstates https://www.facebook.com/illudermaUCAAU https://www.facebook.com/awakenxtusa https://groups.google.com/a/chromium.org/g/chromium-reviews/c/8NMUVKgd-FA https://groups.google.com/g/microsoft.public.project/c/0UZQQKOZF58 https://groups.google.com/g/comp.editors/c/r_BcRRrvGhs https://medium.com/@illuderma/illuderma-reviews-fda-approved-breakthrough-or-clever-skincare-scam-36088ae82c3e https://medium.com/@claritoxpros/claritox-pro-reviews-legitimate-or-deceptive-dr-warns-of-potential-dangers-d5ff3867b34d https://medium.com/@thedetoxall17/detoxall-17-reviews-scam-alert-or-legit-detox-solution-customer-report-inside-1fd4c6920c9e https://groups.google.com/a/chromium.org/g/chromium-reviews/c/RONgLAl6vwM https://groups.google.com/g/microsoft.public.project/c/TgtOMRFt6nQ https://groups.google.com/g/comp.editors/c/fUfg0L2YfzU https://crediblehealths.blogspot.com/2023/12/revitalize-with-restore-cbd-gummies.html https://community.weddingwire.in/forum/restore-cbd-gummies-uncovered-fda-approved-breakthrough-or-deceptive-wellness-scam--t206896 https://restorecbdgummies.bandcamp.com/album/restore-cbd-gummies-uncovered-fda-approved https://my-restore-cb.clubeo.com/page/restore-cbd-gummies-reviews-customer-alert-drs-warning-genuine-or-wellness-hoax.html https://my-restore-cb.clubeo.com/page/restore-cbd-gummies-reviews-scam-alert-or-legit-relief-solution-customer-report-inside.html https://medium.com/@restorecbdgum/restore-cbd-gummies-reviews-warning-2023-update-real-or-a-powerful-relief-hoax-caution-350b61472a3f https://devfolio.co/@restorecbdgum https://restore-cbd-gummies-9.jimdosite.com/ https://devfolio.co/project/new/restore-cbd-gummies-reviews-scam-or-legit-custo-7bd6 https://groups.google.com/a/chromium.org/g/chromium-reviews/c/R0enUCvfs8s https://groups.google.com/g/microsoft.public.project/c/miJma2yOMDQ https://groups.google.com/g/comp.os.vms/c/S_HG94aaKFo https://groups.google.com/g/mozilla.dev.platform/c/qb6WpMUYLu0 https://hellobiz.in/restore-cbd-gummies-reviews-warning-2023-update-genuine-wellness-or-another-hoax-caution-211948390 https://pdfhost.io/v/ir5l.cseV_Restore_CBD_Gummies_Reviews_WARNING_2023_Update_Genuine_Wellness_or_Another_Hoax_Caution https://odoe.powerappsportals.us/en-US/forums/general-discussion/7c8b3f62-6d96-ee11-a81c-001dd8066f2b https://gamma.app/public/Restore-CBD-Gummies-ssh57nprs2l6xgq https://restorecbdgummies.quora.com/ https://www.facebook.com/RestoreCBDGummiesUS https://groups.google.com/g/restorecbdgum/c/9KHVNp3oy3E https://sites.google.com/view/restorecbdgummiesreviewsfdaapp/home https://experiment.com/projects/pjyhtzvpcvllopsglcph/methods https://lookerstudio.google.com/reporting/e5e9f52d-ae52-4c84-96c6-96b97932215f/page/XtkkD https://restore-cbd-gummies-reviews-is-it-a-sca.webflow.io/ https://colab.research.google.com/drive/1xZoc6E2H-jliBSZRVl0vnVqrkc3ix4YU https://soundcloud.com/restore-cbd-gummies-821066674/restore-cbd-gummies https://www.eventcreate.com/e/restore-cbd-gummies-reviews https://restorecbdgummies.godaddysites.com/ https://sketchfab.com/3d-models/restore-cbd-gummies-reviews-fda-approved-7cfe1fb8b003481c81689dd9489d2812 https://www.scoop.it/topic/restore-cbd-gummies-by-restore-cbd-gummies-9 https://events.humanitix.com/restore-cbd-gummies https://communityforums.atmeta.com/t5/General-Development/Restore-CBD-Gummies/m-p/1113602
  • Topics

×
×
  • Create New...

Important Information

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