Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.17.1] Forge Capability - How to save?


chickenwand3
 Share

Recommended Posts

Hey guys I have created a mod that assigns levels to mobs and scales them up using capabilities, everything works great but because of the recent changes to capabilities I am unable to find examples on how to save the level of my mobs so that it remains the same if I restart the server. I will upload all my files relating to the capability and hope you guys can lead me in the right direction :)
 

package com.chickenwand3.rpgmod.core.capabilities.entity;

import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.capabilities.CapabilityManager;

@SuppressWarnings("removal")
public class CapabilityMobLevel {

    @CapabilityInject(MobLevel.class)
    public static Capability<MobLevel> MOB_LEVEL_CAPABILITY = null;

    public static void register() {
        CapabilityManager.INSTANCE.register(MobLevel.class);
    }
}
package com.chickenwand3.rpgmod.core.capabilities.entity;

public class DefaultMobLevel implements MobLevel {

    public int mobLevel;
    public float mobMaxHealth;
    public float mobCurrentHealth;
    public boolean crazy;
    
    public boolean isCrazy() {
    	return crazy;
    }
    
    public float getMaxHealth() {
    	return mobMaxHealth;
    }
    
    public float getCurrentHealth() {
    	return mobCurrentHealth;
    }
}
package com.chickenwand3.rpgmod.core.capabilities.entity;

public interface MobLevel {
}
package com.chickenwand3.rpgmod.core.capabilities.entity;

import com.chickenwand3.rpgmod.RPGMod;

import net.minecraft.resources.ResourceLocation;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.monster.Zombie;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = RPGMod.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class MobLevelEventHandler {
	@SubscribeEvent
	public static void onAttachCapabilitiesEvent(AttachCapabilitiesEvent<Entity> event) {
		if (event.getObject() instanceof Mob && !event.getObject().getCommandSenderWorld().isClientSide) {
			MobLevelProvider providerMobLevel = new MobLevelProvider();
			event.addCapability(new ResourceLocation(RPGMod.MODID, "moblevel"), providerMobLevel);
			event.addListener(providerMobLevel::invalidate);
		}
	}

	@SubscribeEvent
	public static void OnSpawn(final EntityJoinWorldEvent event) {
		if (event.getEntity()instanceof Mob target && !event.getWorld().isClientSide) {
			target.getCapability(CapabilityMobLevel.MOB_LEVEL_CAPABILITY).ifPresent(mobLevel -> {
				DefaultMobLevel actualMobLevel = (DefaultMobLevel) mobLevel;
				actualMobLevel.mobLevel = (randomizeMobLevel());

				if (superCrazy(actualMobLevel.mobLevel)) {
					actualMobLevel.crazy = true;
				}

				if (actualMobLevel.crazy) {

					if (!target.getMainHandItem().isEmpty()) {
						target.getMainHandItem().enchant(Enchantments.FIRE_ASPECT, 1);
					}
					if (event.getEntity()instanceof Zombie zombie) {
						zombie.getAttribute(Attributes.SPAWN_REINFORCEMENTS_CHANCE).setBaseValue(0.99D);
					}
					System.out.println("Super Crazy " + target.getName() + " has spawned!");
				}

				actualMobLevel.mobMaxHealth = (target.getMaxHealth() * actualMobLevel.mobLevel * 2);
				actualMobLevel.mobCurrentHealth = actualMobLevel.mobMaxHealth;
				target.getAttribute(Attributes.MOVEMENT_SPEED)
						.setBaseValue(target.getAttributeValue(Attributes.MOVEMENT_SPEED)
								* (1 + (actualMobLevel.mobLevel - 1.0) / 10.0));

				if (target.getAttribute(Attributes.ATTACK_DAMAGE) != null) {
					target.getAttribute(Attributes.ATTACK_DAMAGE)
							.setBaseValue(target.getAttributeValue(Attributes.ATTACK_DAMAGE)
									* (1 + (actualMobLevel.mobLevel - 1.0) / 2.0));
				}

			});
		}
	}

	private static int randomizeMobLevel() {
		boolean roll = true;
		int level = 1;
		while (roll) {
			if (Math.random() > .5) {
				level += 1;
				roll = true;
			} else {
				roll = false;
			}
		}
		return level;
	}

	private static boolean superCrazy(int level) {
		boolean result = false;
		if (level >= 5) {
			if (Math.random() < .25) {
				result = true;
			} else
				result = false;
		}
		return result;
	}

}
package com.chickenwand3.rpgmod.core.capabilities.entity;

import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import net.minecraftforge.common.util.LazyOptional;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class MobLevelProvider implements ICapabilitySerializable<CompoundTag> {
    private final DefaultMobLevel mobLevel = new DefaultMobLevel();
    private final LazyOptional<MobLevel> mobLevelOptional = LazyOptional.of(() -> mobLevel);

    public void invalidate() {
        mobLevelOptional.invalidate();
    }

    @Nonnull
    @Override
    public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
        return mobLevelOptional.cast();
    }

    @Override
    public CompoundTag serializeNBT() {
        if (CapabilityMobLevel.MOB_LEVEL_CAPABILITY == null) {
            return new CompoundTag();
        } else {
            CompoundTag compoundNBT = new CompoundTag();
            compoundNBT.putInt("mobLevel", mobLevel.mobLevel);
            compoundNBT.putFloat("mobCurrentHealth", mobLevel.mobCurrentHealth);
            compoundNBT.putFloat("mobMaxHealth", mobLevel.mobMaxHealth);
            compoundNBT.putBoolean("crazy", mobLevel.crazy);
            return compoundNBT;
        }
    }
    

    @Override
    public void deserializeNBT(CompoundTag nbt) {
        if (CapabilityMobLevel.MOB_LEVEL_CAPABILITY != null) {
            mobLevel.mobLevel = (nbt.getInt("mobLevel"));
            
            float mobCurrentHealth = nbt.getFloat("mobCurrentHealth");
            mobLevel.mobCurrentHealth = (mobCurrentHealth);
            
            float mobMaxHealth = nbt.getFloat("mobMaxHealth");
            mobLevel.mobMaxHealth = (mobMaxHealth);
            
            boolean crazy = nbt.getBoolean("crazy");
            mobLevel.crazy = (crazy);
        }
    }
}

 

Link to comment
Share on other sites

4 hours ago, chickenwand3 said:

I will upload all my files relating to the capability and hope you guys can lead me in the right direction

Is that a question?

If yes, your capability should be saved since your CapabilityProvider implements ICapabilitySerializable

Link to comment
Share on other sites

Yeah its a question sorry for phrasing it weird, currently everytime I restart the server the mobs .mobLevel is being reset because it isn't saving. Im trying to decipher why this is happening and how to make it so that the .mobLevel for all the mobs in the server persists after a server restart :)

Link to comment
Share on other sites

https://pastebin.com/LvSbvYhL
 

@Override
    public CompoundTag serializeNBT() {
    	System.out.println("It serialized");
        if (CapabilityMobLevel.MOB_LEVEL_CAPABILITY == null) {
        	System.out.println("It made a new compound");
            return new CompoundTag();
        } else {
        	System.out.println("It serialized the values");
            CompoundTag compoundNBT = new CompoundTag();
            compoundNBT.putInt("mobLevel", mobLevel.mobLevel);
            compoundNBT.putFloat("mobCurrentHealth", mobLevel.mobCurrentHealth);
            compoundNBT.putFloat("mobMaxHealth", mobLevel.mobMaxHealth);
            compoundNBT.putBoolean("crazy", mobLevel.crazy);
            return compoundNBT;
        }
    }
    

    @Override
    public void deserializeNBT(CompoundTag nbt) {
    	System.out.println("It deserialized");
        if (CapabilityMobLevel.MOB_LEVEL_CAPABILITY != null) {
        	System.out.println("It deserialized the values");
            mobLevel.mobLevel = (nbt.getInt("mobLevel"));
            
            float mobCurrentHealth = nbt.getFloat("mobCurrentHealth");
            mobLevel.mobCurrentHealth = (mobCurrentHealth);
            
            float mobMaxHealth = nbt.getFloat("mobMaxHealth");
            mobLevel.mobMaxHealth = (mobMaxHealth);
            
            boolean crazy = nbt.getBoolean("crazy");
            mobLevel.crazy = (crazy);
        }
    }

It seems like CapabilityMobLevel.MOB_LEVEL_CAPABILITY is always null and that is why it is acting like its a new entity and generating new values
 

Link to comment
Share on other sites

It worked thanks a lot ❤️ I'm gonna paste all of my code for anyone in the future looking to do capabilities

package com.chickenwand3.rpgmod.core.capabilities.entity;

import javax.annotation.Nullable;

import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.CapabilityToken;
import net.minecraftforge.common.capabilities.ICapabilityProvider;

public class CapabilityMobLevel{
	
    public static Capability<MobLevel> MOB_LEVEL_CAPABILITY = CapabilityManager.get(new CapabilityToken<>() {});
    
    public static void register() {
        CapabilityManager.INSTANCE.register(MobLevel.class);
    }
    

}
package com.chickenwand3.rpgmod.core.capabilities.entity;

public class DefaultMobLevel implements MobLevel {

    public int mobLevel;
    public float mobMaxHealth;
    public float mobCurrentHealth;
    public boolean crazy;
    
    public boolean isCrazy() {
    	return crazy;
    }
    
    public float getMaxHealth() {
    	return mobMaxHealth;
    }
    
    public float getCurrentHealth() {
    	return mobCurrentHealth;
    }
}
package com.chickenwand3.rpgmod.core.capabilities.entity;

public interface MobLevel {
}
package com.chickenwand3.rpgmod.core.capabilities.entity;

import com.chickenwand3.rpgmod.RPGMod;

import net.minecraft.resources.ResourceLocation;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.monster.Zombie;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = RPGMod.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class MobLevelEventHandler {
	@SubscribeEvent
	public static void onAttachCapabilitiesEvent(AttachCapabilitiesEvent<Entity> event) {
		if (event.getObject() instanceof Mob && !event.getObject().getCommandSenderWorld().isClientSide) {
			MobLevelProvider providerMobLevel = new MobLevelProvider();
			event.addCapability(new ResourceLocation(RPGMod.MODID, "moblevel"), providerMobLevel);
			event.addListener(providerMobLevel::invalidate);
		}
	}
	
	@SubscribeEvent
	public void registerCaps(RegisterCapabilitiesEvent event) {
	    event.register(MobLevel.class);
	}
	
	
	

	@SubscribeEvent
	public static void OnSpawn(final EntityJoinWorldEvent event) {
		if (event.getEntity()instanceof Mob target && !event.getWorld().isClientSide) {
			target.getCapability(CapabilityMobLevel.MOB_LEVEL_CAPABILITY).ifPresent(mobLevel -> {
				DefaultMobLevel actualMobLevel = (DefaultMobLevel) mobLevel;
				
				if (actualMobLevel.mobLevel < 1) {
					actualMobLevel.mobLevel = (randomizeMobLevel());
				}

				if (superCrazy(actualMobLevel.mobLevel)) {
					actualMobLevel.crazy = true;
				}

				if (actualMobLevel.crazy) {

					if (!target.getMainHandItem().isEmpty()) {
						target.getMainHandItem().enchant(Enchantments.FIRE_ASPECT, 1);
					}
					if (event.getEntity()instanceof Zombie zombie) {
						zombie.getAttribute(Attributes.SPAWN_REINFORCEMENTS_CHANCE).setBaseValue(0.99D);
					}
					System.out.println("Super Crazy " + target.getName() + " has spawned!");
				}

				actualMobLevel.mobMaxHealth = (target.getMaxHealth() * actualMobLevel.mobLevel * 2);
				actualMobLevel.mobCurrentHealth = actualMobLevel.mobMaxHealth;
				target.getAttribute(Attributes.MOVEMENT_SPEED)
						.setBaseValue(target.getAttributeValue(Attributes.MOVEMENT_SPEED)
								* (1 + (actualMobLevel.mobLevel - 1.0) / 10.0));

				if (target.getAttribute(Attributes.ATTACK_DAMAGE) != null) {
					target.getAttribute(Attributes.ATTACK_DAMAGE)
							.setBaseValue(target.getAttributeValue(Attributes.ATTACK_DAMAGE)
									* (1 + (actualMobLevel.mobLevel - 1.0) / 2.0));
				}

			});
		}
	}

	private static int randomizeMobLevel() {
		boolean roll = true;
		int level = 1;
		while (roll) {
			if (Math.random() > .5) {
				level += 1;
				roll = true;
			} else {
				roll = false;
			}
		}
		return level;
	}

	private static boolean superCrazy(int level) {
		boolean result = false;
		if (level >= 5) {
			if (Math.random() < .25) {
				result = true;
			} else
				result = false;
		}
		return result;
	}

}
package com.chickenwand3.rpgmod.core.capabilities.entity;

import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import net.minecraftforge.common.util.LazyOptional;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class MobLevelProvider implements ICapabilitySerializable<CompoundTag> {
    private final DefaultMobLevel mobLevel = new DefaultMobLevel();
    private final LazyOptional<MobLevel> mobLevelOptional = LazyOptional.of(() -> mobLevel);

    public void invalidate() {
        mobLevelOptional.invalidate();
    }

    @Nonnull
    @Override
    public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
        return mobLevelOptional.cast();
    }

    @Override
    public CompoundTag serializeNBT() {
    	System.out.println("It serialized");
        if (CapabilityMobLevel.MOB_LEVEL_CAPABILITY == null) {
        	System.out.println("It made a new compound");
            return new CompoundTag();
        } else {
        	System.out.println("It serialized the values");
            CompoundTag compoundNBT = new CompoundTag();
            compoundNBT.putInt("mobLevel", mobLevel.mobLevel);
            compoundNBT.putFloat("mobCurrentHealth", mobLevel.mobCurrentHealth);
            compoundNBT.putFloat("mobMaxHealth", mobLevel.mobMaxHealth);
            compoundNBT.putBoolean("crazy", mobLevel.crazy);
            return compoundNBT;
        }
    }
    

    @Override
    public void deserializeNBT(CompoundTag nbt) {
    	System.out.println("It deserialized");
        if (CapabilityMobLevel.MOB_LEVEL_CAPABILITY != null) {
        	System.out.println("It deserialized the values");
            mobLevel.mobLevel = (nbt.getInt("mobLevel"));
            
            float mobCurrentHealth = nbt.getFloat("mobCurrentHealth");
            mobLevel.mobCurrentHealth = (mobCurrentHealth);
            
            float mobMaxHealth = nbt.getFloat("mobMaxHealth");
            mobLevel.mobMaxHealth = (mobMaxHealth);
            
            boolean crazy = nbt.getBoolean("crazy");
            mobLevel.crazy = (crazy);
        }
    }
}

 

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
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.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Ahh ok  But also in mods with custom armor you normally use resourcepacks for the model (every mod has a built-in resource pack), so there really is no need. If you want to do it anyway ... it's your choice 
    • Well, im just learning) Wanna make my own mods in future.
    • Hi! You don't need an extra Mod to do this, you can just use a resource pack and replace the armor texture and model
    • hello. I try to create my custom chest BUT that's make me crazy. 1.if I put an item in my custom chest it become doubled, and if I click it ,it will be dispeared.:( 2.the custom chest what i made use the same container in different blocks.   TileEntity: public class SFCTileEntity extends TileEntity implements INamedContainerProvider { public static final int NUMBER_OF_SLOTS = 27; public SFCTileEntity() { super(TileEntityTypeRegistry.TileEntity.get()); chestContents = ChestContents.createForTileEntity(NUMBER_OF_SLOTS, this::canPlayerAccessInventory, this::setChanged); } public boolean canPlayerAccessInventory(PlayerEntity player) { if (this.level.getBlockEntity(this.worldPosition) != this) return false; final double X_CENTRE_OFFSET = 0.5; final double Y_CENTRE_OFFSET = 0.5; final double Z_CENTRE_OFFSET = 0.5; final double MAXIMUM_DISTANCE_SQ = 8.0 * 8.0; return player.distanceToSqr(worldPosition.getX() + X_CENTRE_OFFSET, worldPosition.getY() + Y_CENTRE_OFFSET, worldPosition.getZ() + Z_CENTRE_OFFSET) < MAXIMUM_DISTANCE_SQ; } private static final String CHESTCONTENTS_INVENTORY_TAG = "contents"; @Override public CompoundNBT save(CompoundNBT parentNBTTagCompound) { super.save(parentNBTTagCompound); CompoundNBT inventoryNBT = chestContents.serializeNBT(); parentNBTTagCompound.put(CHESTCONTENTS_INVENTORY_TAG, inventoryNBT); return parentNBTTagCompound; } @Override public void load(BlockState blockState, CompoundNBT parentNBTTagCompound) { super.load(blockState, parentNBTTagCompound); CompoundNBT inventoryNBT = parentNBTTagCompound.getCompound(CHESTCONTENTS_INVENTORY_TAG); chestContents.deserializeNBT(inventoryNBT); } @Override @Nullable public SUpdateTileEntityPacket getUpdatePacket() { CompoundNBT nbtTagCompound = new CompoundNBT(); save(nbtTagCompound); int tileEntityType = 42; return new SUpdateTileEntityPacket(this.worldPosition, tileEntityType, nbtTagCompound); } @Override public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) { BlockState blockState = level.getBlockState(worldPosition); load(blockState, pkt.getTag()); } @Override public CompoundNBT getUpdateTag() { CompoundNBT nbtTagCompound = new CompoundNBT(); save(nbtTagCompound); return nbtTagCompound; } /* Populates this TileEntity with information from the tag, used by vanilla to transmit from server to client * The vanilla default is suitable for this example but I've included an explicit definition anyway. */ @Override public void handleUpdateTag(BlockState blockState, CompoundNBT tag) { this.load(blockState, tag); } @Override public ITextComponent getDisplayName() { return null; } @Nullable @Override public Container createMenu(int windowID, PlayerInventory playerInventory, PlayerEntity playerEntity) { return SFContainer.createContainerServerSide(windowID, playerInventory, chestContents); } public static ChestContents getChestContents() { return chestContents; } private static ChestContents chestContents; }   Container: public class SFContainer extends Container { private static final int HOTBAR_SLOT_COUNT = 9; private static final int PLAYER_INVENTORY_ROW_COUNT = 3; private static final int PLAYER_INVENTORY_COLUMN_COUNT = 9; private static final int PLAYER_INVENTORY_SLOT_COUNT = PLAYER_INVENTORY_COLUMN_COUNT * PLAYER_INVENTORY_ROW_COUNT; private static final int VANILLA_SLOT_COUNT = HOTBAR_SLOT_COUNT + PLAYER_INVENTORY_SLOT_COUNT; private static final int VANILLA_FIRST_SLOT_INDEX = 0; private static final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT; private static final int TE_INVENTORY_SLOT_COUNT = SFCTileEntity.NUMBER_OF_SLOTS; public static final int TILE_INVENTORY_YPOS = 18; public static final int PLAYER_INVENTORY_YPOS = 86; public SFContainer(int windowID, PlayerInventory playerInventory, ChestContents chestContents) { super(ContainerTypeRegistry.Container.get(), windowID); PlayerInvWrapper playerInventoryForge = new PlayerInvWrapper(playerInventory); this.chestContents = chestContents; final int SLOT_X_SPACING = 18; final int SLOT_Y_SPACING = 18; final int HOTBAR_XPOS = 8; final int HOTBAR_YPOS = 144; for (int x = 0; x < HOTBAR_SLOT_COUNT; x++) { int slotNumber = x; addSlot(new SlotItemHandler(playerInventoryForge, slotNumber, HOTBAR_XPOS + SLOT_X_SPACING * x, HOTBAR_YPOS)); } final int PLAYER_INVENTORY_XPOS = 8; // Add the rest of the player's inventory to the gui for (int y = 0; y < PLAYER_INVENTORY_ROW_COUNT; y++) { for (int x = 0; x < PLAYER_INVENTORY_COLUMN_COUNT; x++) { int slotNumber = HOTBAR_SLOT_COUNT + y * PLAYER_INVENTORY_COLUMN_COUNT + x; int xpos = PLAYER_INVENTORY_XPOS + x * SLOT_X_SPACING; int ypos = PLAYER_INVENTORY_YPOS + y * SLOT_Y_SPACING; addSlot(new SlotItemHandler(playerInventoryForge, slotNumber, xpos, ypos)); } } // Add the tile inventory container to the gui for(int i = 0;i<9;i++){ addSlot(new Slot(chestContents, i, 8+18*i, 18)); addSlot(new Slot(chestContents, i+9, 8+18*i, 36)); addSlot(new Slot(chestContents, i+18, 8+18*i, 54)); } } public static SFContainer createContainerServerSide(int windowID, PlayerInventory playerInventory, ChestContents chestContents) { return new SFContainer(windowID, playerInventory, chestContents); } public static SFContainer createContainerClientSide(int windowID, PlayerInventory playerInventory, net.minecraft.network.PacketBuffer extraData) { ChestContents chestContents = ChestContents.createForClientSideContainer(SFCTileEntity.NUMBER_OF_SLOTS); return new SFContainer(windowID, playerInventory, chestContents); } @Override public boolean stillValid(PlayerEntity playerEntity) { return chestContents.stillValid(playerEntity); } @Override public ItemStack quickMoveStack(PlayerEntity playerEntity, int sourceSlotIndex) { Slot sourceSlot = getSlot(sourceSlotIndex); if (sourceSlot == null || !sourceSlot.hasItem()) return ItemStack.EMPTY; //EMPTY_ITEM ItemStack sourceStack = sourceSlot.getItem(); ItemStack copyOfSourceStack = sourceStack.copy(); // Check if the slot clicked is one of the vanilla container slots if (sourceSlotIndex >= VANILLA_FIRST_SLOT_INDEX && sourceSlotIndex < VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT) { // This is a vanilla container slot so merge the stack into the tile inventory if (!moveItemStackTo(sourceStack, TE_INVENTORY_FIRST_SLOT_INDEX, TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT, false)){ return ItemStack.EMPTY; // EMPTY_ITEM } } else if (sourceSlotIndex >= TE_INVENTORY_FIRST_SLOT_INDEX && sourceSlotIndex < TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT) { // This is a TE slot so merge the stack into the players inventory if (!moveItemStackTo(sourceStack, VANILLA_FIRST_SLOT_INDEX, VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT, false)) { return ItemStack.EMPTY; } } else { LOGGER.warn("Invalid slotIndex:" + sourceSlotIndex); return ItemStack.EMPTY; } // If stack size == 0 (the entire stack was moved) set slot contents to null if (sourceStack.getCount() == 0) { sourceSlot.mayPlace(ItemStack.EMPTY); } else { sourceSlot.setChanged(); } sourceSlot.onTake(playerEntity, sourceStack); return copyOfSourceStack; } // pass the close container message to the parent inventory (not strictly needed for this example) // see ContainerChest and TileEntityChest - used to animate the lid when no players are accessing the chest any more @Override public void removed(PlayerEntity playerIn) { super.removed(playerIn); } private ChestContents chestContents; private static final Logger LOGGER = LogManager.getLogger(); }  
    • Posting again to finish this thread as I've found a solution for my problem. Don't know why it was having an issue with Java but uninstalled my most recent update of java and switched back to Java 17.02 Here's a link to the version of Java I'm now using https://download.oracle.com/java/17/latest/jdk-17_windows-x64_bin.exe Hope it works for whoever is looking for a solution.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.