Jump to content

Recommended Posts

Posted

I am trying to put all my Items and Blocks into there own section on Creative Mode but for some reason Blocks are not working with it the Item section is working find but when I click on the second option witch is the Blocks Option it crashes and closes:/ here is my code

 

CreativeTabBlocks

 

 

package com.MoreEverything.creativetabs;

 

import java.util.List;

 

import com.MoreEverything.Item.MoreItems;

import com.MoreEverything.Item.Ruby;

import com.MoreEverything.block.MoreBlocks;

import com.MoreEverything.block.RandomOreBlock;

import com.MoreEverything.block.RubyBlock;

import com.MoreEverything.block.RubyOreBlock;

import com.MoreEverything.block.TinOreBlock;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.enchantment.Enchantment;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

 

public class CreativeTabBlocks extends CreativeTabs {

 

    public CreativeTabBlocks(int id, String unlocalizedName) {

 

        super(id, unlocalizedName);

    }

 

    @SideOnly(Side.CLIENT)

    public Item getTabIconItem() {

 

        return Item.getItemFromBlock(MoreBlocks.RubyBlock);

    }

   

    @SideOnly(Side.CLIENT)

    public void displayAllReleventItems(List itemList) {

 

        itemList.add(new ItemStack(MoreBlocks.RubyOreBlock));

        itemList.add(new ItemStack(MoreBlocks.TinOreBlock));

        itemList.add(new ItemStack(MoreBlocks.RandomOreBlock));

        itemList.add(new ItemStack(MoreBlocks.RubyBlock));

    }   

   

}

 

 

 

Blocks

 

 

RubyOreBlock

 

 

package com.MoreEverything.block;

 

import java.util.Random;

 

import com.MoreEverything.lib.Strings;

 

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.event.FMLPreInitializationEvent;

import cpw.mods.fml.common.registry.GameRegistry;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.init.Blocks;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraftforge.common.MinecraftForge;

 

public class RubyOreBlock extends Block {

 

public static Block RubyOreBlock;

private CreativeTabs tabBlocks;

 

public RubyOreBlock(Material p_i45394_1_) {

super(p_i45394_1_);

// TODO Auto-generated constructor stub

}

 

    {

        this.setBlockName(Strings.RubyOreBlock);

        this.setHardness(5.0f);

        this.setCreativeTab(tabBlocks);

        this.setResistance(3f);

        this.setStepSound(Block.soundTypeStone);

        this.setHarvestLevel("pickaxe", 2);

    }

   

  }

 

 

 

TinOreBlock

 

 

package com.MoreEverything.block;

 

import java.util.Random;

 

import com.MoreEverything.lib.Strings;

 

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.event.FMLPreInitializationEvent;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.init.Blocks;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraftforge.common.MinecraftForge;

 

public class TinOreBlock extends Block {

 

    public static Block TinOreBlock;

    private CreativeTabs tabBlocks;

 

public TinOreBlock(Material p_i45394_1_) {

super(p_i45394_1_);

// TODO Auto-generated constructor stub

}

 

{

        this.setBlockName(Strings.TinOreBlock);

        this.setCreativeTab(tabBlocks);

        this.setHardness(3.0f);

        this.setResistance(3.0f);

        this.setStepSound(Block.soundTypeStone);

        this.setHarvestLevel("pickaxe", 1);

    }

 

}

 

 

 

RandomOreBlock

 

 

package com.MoreEverything.block;

 

import java.util.Random;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

 

import com.MoreEverything.lib.Strings;

 

public class RandomOreBlock extends Block {

 

public static Block RandomOreBlock;

private CreativeTabs tabStandard;

 

    public RandomOreBlock(Material p_i45394_1_) {

super(p_i45394_1_);

// TODO Auto-generated constructor stub

}

 

{

        this.setBlockName(Strings.RandomOreBlock);

        this.setCreativeTab(tabStandard);

        this.setHardness(4.0f);

        this.setResistance(3f);

        this.setStepSound(Block.soundTypeStone);

        this.setHarvestLevel("pickaxe", 2);

    }

 

private Item itemDropped = null;

private int quantityDropped = 0;

 

@Override

public Item getItemDropped(int metadata, Random random, int fortune)

{

 

       

switch(random.nextInt(20))

{

case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10:

return Items.coal;

case 11: case 12: case 13:

return Items.iron_ingot;

case 14: case 15:

return Items.gold_ingot;

case 16:

return Items.diamond;

case 17:

return Items.emerald;

default:

return Items.egg;

}

}

 

@Override

        public int quantityDropped(int meta, int fortune, Random random)

{

if(itemDropped == Items.coal)

{

quantityDropped = 5;

}

 

else if(itemDropped == Items.iron_ingot)

{

quantityDropped = 3;

}

 

else if(itemDropped == Items.gold_ingot)

{

quantityDropped = 2;

}

 

else if(itemDropped == Items.diamond)

{

quantityDropped = 1;

}

 

else if(itemDropped == Items.emerald)

{

quantityDropped = 1;

}

 

else

{

return quantityDropped = 1;

}

return quantityDropped;

 

 

}

 

}

 

 

 

RubyBlock

 

 

package com.MoreEverything.block;

 

import java.util.Random;

 

import com.MoreEverything.lib.Strings;

 

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.event.FMLPreInitializationEvent;

import cpw.mods.fml.common.registry.GameRegistry;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.init.Blocks;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraftforge.common.MinecraftForge;

 

public class RubyBlock extends Block {

 

public static Block RubyBlock;

private CreativeTabs tabBlocks;

 

 

public RubyBlock(Material p_i45394_1_) {

super(p_i45394_1_);

// TODO Auto-generated constructor stub

}

 

    {

        this.setBlockName(Strings.RubyBlock);

        this.setHardness(5.0f);

        this.setCreativeTab(tabBlocks);

        this.setResistance(3f);

        this.setStepSound(Block.soundTypeStone);

        this.setHarvestLevel("pickaxe", 2);

    }

 

public static void mainRegistry() {

// TODO Auto-generated method stub

 

}

   

  }

 

 

 

 

 

 

Please help I really want this to work :)

Posted

Crash log? can we also see your main mod file (where you initialize your custom creative tabs)

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

I don't know why it won't work just want to make it tidy all the content from my mod in it's own creativetabs :/

 

Here is my Main Class

 

 

package com.OresandTools.Main;

 

import com.OresandTools.CreativeTabs.CreativeTabItems;

import com.OresandTools.CreativeTabs.CreativeTabOres;

import com.OresandTools.CreativeTabs.CreativeTabTools;

import com.OresandTools.Items.Ruby;

import com.OresandTools.Lib.Strings;

import com.OresandTools.World.OresWorldGenerator;

import com.OresandTools.World.RubyOre;

import com.OresandTools.World.TinOre;

 

import net.minecraft.block.Block;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.item.Item;

import net.minecraftforge.common.util.EnumHelper;

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.Mod.EventHandler;

import cpw.mods.fml.common.Mod.Instance;

import cpw.mods.fml.common.SidedProxy;

import cpw.mods.fml.common.event.FMLInitializationEvent;

import cpw.mods.fml.common.event.FMLPostInitializationEvent;

import cpw.mods.fml.common.event.FMLPreInitializationEvent;

import cpw.mods.fml.common.registry.GameRegistry;

import cpw.mods.fml.common.registry.LanguageRegistry;

 

@Mod(modid = Strings.MODID, name = Strings.name, version = Strings.version)

 

public class MainRegistry {

 

@SidedProxy(clientSide = "com.OresandTools.Main.ClientProxy", serverSide = "com.OresandTools.Main.ServerProxy")

public static ServerProxy proxy;

 

@Instance(Strings.MODID)

public static MainRegistry modInstance;

 

 

 

/**

* Loads before

* @param PreEvent

*/

 

 

//Tools

//public static final Item.ToolMaterial Rubym = EnumHelper.addToolMaterial("RubyM", 2, 350, 5.0F, 2.0F, 16);

 

//public static Item RubyPickaxe = new RubyPickaxe(5000, Rubym);

//public static Item RubySpade = new RubySpade(5001, Rubym);

//public static Item RubyAxe = new RubyAxe(5002, Rubym);

//public static Item RubySword = new RubySword(5003, Rubym);

//public static Item RubyHoe = new RubyHoe(5004, Rubym);

 

 

//Creative Tabs

 

public static final CreativeTabs tabItems = new CreativeTabItems(CreativeTabs.getNextID(), "Items");

public static final CreativeTabs tabTools = new CreativeTabTools(CreativeTabs.getNextID(), "Tools");

public static final CreativeTabs tabOres = new CreativeTabOres(CreativeTabs.getNextID(), "Ores");

 

 

@Mod.EventHandler

public static void PreLoad(FMLPreInitializationEvent PreEvent){

//Tabs

 

//Ore

RubyOre.mainRegistry();

 

TinOre.mainRegistry();

 

//Items

Ruby.mainRegistry();

 

//Blocks

 

 

//Tools

 

 

//Crafting

CraftingHandler.init();

 

//Proxy's

proxy.registerRenderThings();

 

//WorldOre

OresWorldGenerator.mainRegistry();

}

 

 

/**

* Loads during

* @param event

*/

 

@EventHandler

public static void Load(FMLInitializationEvent event){

 

}

 

/**

* Loads after

* @param PostEvent

*/

 

@EventHandler

public static void PostLoad(FMLPostInitializationEvent PostEvent){

 

}

//Tool Registry

//public MainRegistry() {

//GameRegistry.registerItem(RubyPickaxe, "Ruby Pickaxe");

//GameRegistry.registerItem(RubySpade, "Ruby Spade");

//GameRegistry.registerItem(RubyAxe, "Ruby Axe");

//GameRegistry.registerItem(RubySword, "Ruby Sword");

//GameRegistry.registerItem(RubyHoe, "Ruby Hoe");

 

 

//Creative Tab Language Registry

 

 

//Tool Language Registry

//LanguageRegistry.addName(RubyPickaxe, "Ruby Pickaxe");

//LanguageRegistry.addName(RubySpade, "Ruby Shovel");

//LanguageRegistry.addName(RubyAxe, "Ruby Axe");

//LanguageRegistry.addName(RubySword, "Ruby Sword");

//LanguageRegistry.addName(RubyHoe, "Ruby Hoe");

}

 

 

//}

 

 

 

And here is the class where I am putting the block

 

 

package com.OresandTools.CreativeTabs;

 

import java.util.List;

 

import com.OresandTools.Blocks.RubyOreBlock;

import com.OresandTools.Items.Ruby;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.block.Block;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.enchantment.Enchantment;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

 

public class CreativeTabOres extends CreativeTabs {

 

    private Block RubyOreBlock;

 

public CreativeTabOres(int id, String unlocalizedName) {

 

        super(id, unlocalizedName);

    }

 

    @SideOnly(Side.CLIENT)

    public Item getTabIconItem() {

 

        //return Item.getItemFromBlock(RubyOreBlock.RubyOreBlock);

        return Ruby.Ruby;

    }

   

    @SideOnly(Side.CLIENT)

    public void displayAllReleventItems(List itemList) {

       

        //Adds string with silk touch lv 1

        //ItemStack string = new ItemStack(Items.string);

        //string.addEnchantment(Enchantment.silkTouch, 1);

        //itemList.add(string);

 

        //Adds wooden hoe

        //itemList.add(new ItemStack(RubyOreBlock));

    Item.getItemFromBlock(RubyOreBlock);

       

        //Adds all fishing enchantments

        //this.addEnchantmentBooksToList(itemList, new EnumEnchantmentType[] { EnumEnchantmentType.fishing_rod});

    }   

   

}

 

 

 

And here is the crash log when I run it

 

 

---- Minecraft Crash Report ----

// Ouch. That hurt :(

 

Time: 08/05/14 15:42

Description: Rendering item

 

java.lang.NullPointerException: Rendering item

at net.minecraft.item.ItemStack.getItemDamage(ItemStack.java:266)

at net.minecraft.client.renderer.entity.RenderItem.renderItemIntoGUI(RenderItem.java:415)

at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:560)

at net.minecraft.client.gui.inventory.GuiContainer.func_146977_a(GuiContainer.java:291)

at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:118)

at net.minecraft.client.renderer.InventoryEffectRenderer.drawScreen(InventoryEffectRenderer.java:44)

at net.minecraft.client.gui.inventory.GuiContainerCreative.drawScreen(GuiContainerCreative.java:672)

at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1143)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1024)

at net.minecraft.client.Minecraft.run(Minecraft.java:912)

at net.minecraft.client.main.Main.main(Main.java:112)

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.minecraft.launchwrapper.Launch.launch(Launch.java:134)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at net.minecraft.item.ItemStack.getItemDamage(ItemStack.java:266)

at net.minecraft.client.renderer.entity.RenderItem.renderItemIntoGUI(RenderItem.java:415)

 

-- Item being rendered --

Details:

Item Type: null

Item Aux: ~~ERROR~~ NullPointerException: null

Item NBT: null

Item Foil: ~~ERROR~~ NullPointerException: null

Stacktrace:

at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:560)

at net.minecraft.client.gui.inventory.GuiContainer.func_146977_a(GuiContainer.java:291)

at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:118)

at net.minecraft.client.renderer.InventoryEffectRenderer.drawScreen(InventoryEffectRenderer.java:44)

at net.minecraft.client.gui.inventory.GuiContainerCreative.drawScreen(GuiContainerCreative.java:672)

 

-- Screen render details --

Details:

Screen name: net.minecraft.client.gui.inventory.GuiContainerCreative

Mouse location: Scaled: (206, 36). Absolute: (619, 657)

Screen size: Scaled: (456, 256). Absolute: (1366, 768). Scale factor of 3

 

-- Affected level --

Details:

Level name: MpServer

All players: 1 total; [EntityClientPlayerMP['Player816'/216, l='MpServer', x=-263.75, y=87.65, z=112.91]]

Chunk stats: MultiplayerChunkCache: 225, 225

Level seed: 0

Level generator: ID 00 - default, ver 1. Features enabled: false

Level generator options:

Level spawn location: World: (-256,64,116), Chunk: (at 0,4,4 in -16,7; contains blocks -256,0,112 to -241,255,127), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)

Level time: 4514 game time, 4514 day time

Level dimension: 0

Level storage version: 0x00000 - Unknown?

Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)

Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false

Forced entities: 41 total; [EntitySquid['Squid'/137, l='MpServer', x=-210.07, y=46.00, z=173.55], EntitySheep['Sheep'/70, l='MpServer', x=-309.47, y=66.00, z=74.59], EntitySheep['Sheep'/71, l='MpServer', x=-311.50, y=65.00, z=70.78], EntitySquid['Squid'/66, l='MpServer', x=-317.32, y=45.01, z=176.35], EntitySquid['Squid'/76, l='MpServer', x=-315.46, y=45.40, z=167.72], EntitySquid['Squid'/77, l='MpServer', x=-305.47, y=46.00, z=166.53], EntitySquid['Squid'/131, l='MpServer', x=-204.62, y=49.41, z=174.89], EntitySheep['Sheep'/72, l='MpServer', x=-305.63, y=67.00, z=79.53], EntityBat['Bat'/132, l='MpServer', x=-223.31, y=29.10, z=177.88], EntitySquid['Squid'/73, l='MpServer', x=-314.31, y=44.40, z=153.17], EntitySquid['Squid'/74, l='MpServer', x=-314.37, y=47.38, z=148.90], EntityBat['Bat'/134, l='MpServer', x=-220.19, y=39.43, z=181.34], EntityBat['Bat'/75, l='MpServer', x=-307.61, y=31.00, z=158.94], EntitySquid['Squid'/152, l='MpServer', x=-203.25, y=46.00, z=168.47], EntityClientPlayerMP['Player816'/216, l='MpServer', x=-263.75, y=87.65, z=112.91], EntitySheep['Sheep'/83, l='MpServer', x=-303.09, y=67.00, z=70.97], EntitySquid['Squid'/95, l='MpServer', x=-282.32, y=47.00, z=149.33], EntityBat['Bat'/150, l='MpServer', x=-193.53, y=28.10, z=154.22], EntitySquid['Squid'/98, l='MpServer', x=-275.85, y=48.00, z=159.53], EntitySquid['Squid'/99, l='MpServer', x=-279.54, y=54.32, z=162.61], EntitySquid['Squid'/96, l='MpServer', x=-282.63, y=47.35, z=143.50], EntitySquid['Squid'/97, l='MpServer', x=-277.96, y=49.17, z=154.39], EntitySquid['Squid'/110, l='MpServer', x=-273.19, y=49.38, z=162.53], EntitySquid['Squid'/111, l='MpServer', x=-268.46, y=52.00, z=161.56], EntityBat['Bat'/108, l='MpServer', x=-256.25, y=62.10, z=41.47], EntitySquid['Squid'/109, l='MpServer', x=-269.50, y=52.00, z=158.64], EntityPig['Pig'/119, l='MpServer', x=-246.67, y=64.00, z=75.65], EntityPig['Pig'/118, l='MpServer', x=-241.78, y=64.00, z=66.34], EntitySquid['Squid'/114, l='MpServer', x=-271.47, y=49.31, z=158.43], EntitySquid['Squid'/113, l='MpServer', x=-270.65, y=51.40, z=163.38], EntitySquid['Squid'/112, l='MpServer', x=-266.48, y=55.43, z=161.76], EntitySheep['Sheep'/127, l='MpServer', x=-228.16, y=66.00, z=83.63], EntityBat['Bat'/58, l='MpServer', x=-343.25, y=31.10, z=75.38], EntitySheep['Sheep'/126, l='MpServer', x=-239.75, y=66.00, z=72.59], EntityPig['Pig'/125, l='MpServer', x=-235.78, y=63.00, z=70.81], EntityPig['Pig'/124, l='MpServer', x=-230.47, y=64.00, z=53.34], EntityBat['Bat'/182, l='MpServer', x=-189.86, y=28.27, z=162.24], EntityBat['Bat'/123, l='MpServer', x=-238.25, y=33.10, z=49.47], EntitySheep['Sheep'/121, l='MpServer', x=-246.87, y=64.00, z=79.47], EntityBat['Bat'/60, l='MpServer', x=-343.09, y=33.10, z=71.09], EntitySheep['Sheep'/120, l='MpServer', x=-254.53, y=64.00, z=64.81]]

Retry entities: 0 total; []

Server brand: fml,forge

Server type: Integrated singleplayer server

Stacktrace:

at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:412)

at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2523)

at net.minecraft.client.Minecraft.run(Minecraft.java:934)

at net.minecraft.client.main.Main.main(Main.java:112)

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.minecraft.launchwrapper.Launch.launch(Launch.java:134)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

 

-- System Details --

Details:

Minecraft Version: 1.7.2

Operating System: Windows 8 (amd64) version 6.2

Java Version: 1.7.0_51, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 687312912 bytes (655 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

AABB Pool Size: 14115 (790440 bytes; 0 MB) allocated, 610 (34160 bytes; 0 MB) used

IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94

FML: MCP v9.03 FML v7.2.165.1063 Minecraft Forge 10.12.1.1063 4 mods loaded, 4 mods active

mcp{9.03} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

FML{7.2.165.1063} [Forge Mod Loader] (forgeSrc-1.7.2-10.12.1.1063.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Forge{10.12.1.1063} [Minecraft Forge] (forgeSrc-1.7.2-10.12.1.1063.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

oat{0.0.1 Alpha} [Ores and Tools] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Launched Version: 1.6

LWJGL: 2.9.0

OpenGL: Intel® HD Graphics 4000 GL version 4.0.0 - Build 9.17.10.2828, Intel

Is Modded: Definitely; Client brand changed to 'fml,forge'

Type: Client (map_client.txt)

Resource Packs: []

Current Language: English (US)

Profiler Position: N/A (disabled)

Vec3 Pool Size: 11552 (646912 bytes; 0 MB) allocated, 2934 (164304 bytes; 0 MB) used

Anisotropic Filtering: Off (1)

 

 

 

And here is the RubyOreBlock Class

 

 

package com.OresandTools.Blocks;

 

import java.util.Random;

 

import com.OresandTools.Lib.Strings;

 

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.event.FMLPreInitializationEvent;

import cpw.mods.fml.common.registry.GameRegistry;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.init.Blocks;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraftforge.common.MinecraftForge;

 

public class RubyOreBlock extends Block {

 

public static Block RubyOreBlock;

public CreativeTabs tabOres;

 

 

 

public RubyOreBlock(Material p_i45394_1_) {

super(p_i45394_1_);

// TODO Auto-generated constructor stub

}

 

    {

   

    this.setBlockTextureName(Strings.MODID + ":RubyOreBlock");

    this.setCreativeTab(tabOres);

        this.setBlockName(Strings.RubyOreBlock);

        this.setHardness(5.0f);

        this.setResistance(3f);

        this.setStepSound(Block.soundTypeStone);

        this.setHarvestLevel("pickaxe", 2);

    }

 

public static void mainRegistry() {

GameRegistry.registerBlock(RubyOreBlock, "RubyOreBlock");

 

}

   

  }

 

 

 

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
    • Do you use features of inventory profiles next (ipnext) or is there a change without it?
    • Remove rubidium - you are already using embeddium, which is a fork of rubidium
  • Topics

×
×
  • Create New...

Important Information

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