Jump to content

[mc 1.12.2 - forge 14.23.5.2768] Item Inventory


Recommended Posts

Posted

I'm back from an old mod i've made for mc 1.11.2

 

I've mostly restart from scratch and just rewrite all my class to create my "Bag".

The problem is ... i havn't any error but nothing happend, so i think io just miss something but can't find what is wrong.

 

Main.java

package com.kporal.mcplus;

import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemArmor.ArmorMaterial;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

@Mod( modid = Main.MODID, name = Main.NAME, version = Main.VERSION, acceptedMinecraftVersions = Main.MCVERSION )
public class Main {

	public static final String MODID = "mcplus";
	public static final String NAME = "MCPlus";
	public static final String VERSION = "1.0";
	public static final String MCVERSION = "[1.12.2]";
	
	public static final ArmorMaterial armorMCP = EnumHelper.addArmorMaterial( "armorMCP", MODID + ":dragoon", 1600, new int[] { 4, 8, 10, 4 }, 30, SoundEvents.ITEM_ARMOR_EQIIP_ELYTRA, 4 ).setRepairItem( new ItemStack( Items.EMERALD ));
	public static final ToolMaterial emeraldMCP = EnumHelper.addToolMaterial( "emeraldMCP", 4, 10000, 10.0F, 9.0F, 30 ).setRepairItem( new ItemStack( Items.EMERALD ));
	
	public static Item ehaxe, dragoonHelmet, dragoonChest, dragoonLegs, dragoonBoots, kitbag;
	
	@EventHandler
	public void preInit( FMLPreInitializationEvent event ) {
		ehaxe = new Ehaxe( emeraldMCP );
		dragoonHelmet = new DragoonArmor( armorMCP, EntityEquipmentSlot.HEAD, "dragoon_helmet" );
		dragoonChest = new DragoonArmor( armorMCP, EntityEquipmentSlot.CHEST, "dragoon_chest" );
		dragoonLegs = new DragoonArmor( armorMCP, EntityEquipmentSlot.LEGS, "dragoon_legs" );
		dragoonBoots = new DragoonArmor( armorMCP, EntityEquipmentSlot.FEET, "dragoon_boots" );
		kitbag = new Kitbag();
	}

	@EventHandler
	public void init( FMLInitializationEvent event ) {}
	
}

 

Kitbag.java

package com.kporal.mcplus;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.ICapabilityProvider;

public class Kitbag extends Item {
	
	public Kitbag() {
		
		this.setRegistryName( "kitbag" );
		this.setTranslationKey( "kitbag" );
		this.setCreativeTab( CreativeTabs.TOOLS );
		this.setMaxStackSize( 1 );
		
	}

	public ActionResult<ItemStack> onItemRightClick( World w, EntityPlayer p, EnumHand e ) {
		//NBTTagCompound nbt = new NBTTagCompound();
		//inventory.deserializeNBT( nbt );

		return new ActionResult<ItemStack>( EnumActionResult.PASS, p.getHeldItemMainhand() );
	}

	public void onPlayerStoppedUsing( ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft ) {
		//inventory.serializeNBT();
	}
	
	@Override
	public ICapabilityProvider initCapabilities( ItemStack item, NBTTagCompound nbt ) {
		if( item.getItem() == Main.kitbag ) {
			return new KitbagProvider();
		}
		return null;
	}
	
}

 

KitbagProvider.java

package com.kporal.mcplus;

import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;

public class KitbagProvider implements ICapabilityProvider, ICapabilitySerializable<NBTTagCompound> {
	
	private final ItemStackHandler inventory;
	
	public KitbagProvider() {
		inventory = new ItemStackHandler( 54 );
	}
	
	@Override
	public NBTTagCompound serializeNBT() {
		return inventory.serializeNBT();
	}

	public void deserializeNBT( NBTTagCompound nbt ) {
		inventory.deserializeNBT( nbt );
	}

	@Override
	public boolean hasCapability( Capability<?> capability, EnumFacing facing ) {
		if( capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ) {
			return true;
		}
		return false;
	}

	@Override
	public <T> T getCapability( Capability<T> capability, EnumFacing facing ) {
		if( capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ) {
			return (T) inventory; 
		}
		return null;
	}
	
}

 

KitbagContainer.java

package com.kporal.mcplus;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;

public class KitbagContainer extends Container {

	public KitbagContainer( IItemHandler i, EntityPlayer p ) {
		
		int xPos = 8;
		int yPos = 18;
		int iid = 0;
	
		for( int y = 0; y < 6; ++y ) {
			for( int x = 0; x < 9; ++x ) {
				addSlotToContainer( new SlotItemHandler( i, iid, xPos + x * 18, yPos + y * 18 ));
				iid++;
			}
		}
		
		yPos = 140;
		
		for( int y = 0; y < 3; ++y ) {
			for( int x = 0; x < 9; ++x ) {
				addSlotToContainer( new Slot( p.inventory, x + y * 9 + 9, xPos + x * 18, yPos + y * 18 ));
			}
		}
		
		for( int x = 0; x < 9; ++x ) {
			addSlotToContainer( new Slot( p.inventory, x, xPos + x * 18, 198 ));
		}
		
	}
	
	@Override
	public boolean canInteractWith( EntityPlayer p ) {
		return true;
	}
	
}

 

KitbagGuiHandler.java

package com.kporal.mcplus;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;

public class KitbagGuiHandler implements IGuiHandler {

	@Override
	public Object getServerGuiElement(int ID, EntityPlayer p, World w, int x, int y, int z) {
		return new KitbagContainer( (IItemHandler) p.getHeldItemMainhand().getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null ), p );
	}

	@Override
	public Object getClientGuiElement(int ID, EntityPlayer p, World w, int x, int y, int z) {
		return new KitbagGui( (IItemHandler) p.getHeldItemMainhand().getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null ), p );
	}
	
}

 

KitbagGui.java

package com.kporal.mcplus;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.items.IItemHandler;

public class KitbagGui extends GuiContainer {

	private IItemHandler i;
	
	public KitbagGui( IItemHandler i, EntityPlayer p ) {
		super( new KitbagContainer( i, p ));
		
		this.xSize = 175;
		this.ySize = 221;
		this.i = i;
	}

	@Override
	protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
		GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
		this.mc.getTextureManager().bindTexture( new ResourceLocation( Main.MODID, "textures/gui/container/kitbag.png" ) );
		this.drawTexturedModalRect( this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize );
	}
	
}

 

The game start without any error, my item is registered, i can't take it / craft it, absolutely no issue, but nothing happend on right click, so if any one see where i'm wrong and can tell me what's my error !

Posted

Update to a modern version of Minecraft. Anything under 1.14.4 isn't supported anymore because its too old.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • that happens every time I enter a new dimension.
    • This is the last line before the crash: [ebwizardry]: Synchronising spell emitters for PixelTraveler But I have no idea what this means
    • What in particular? I barely used that mod this time around, and it's never been a problem in the past.
    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } } my entire project:https://github.com/kevin051606/DERP-Mod/tree/Derp-1.0-1.20
  • Topics

×
×
  • Create New...

Important Information

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