Jump to content

Recommended Posts

Posted

So, I was trying to add a custom crafting table but when I place it and right-click it it will for 1 frame (I think) show the gui and then close it again, I know it shows something because when I right-click I get black stripes for a short amount of time (< 1 second) and when I immediately press E it wont open my inventory, my block class:

public class CheeseBlocks {

public static Block CHEESE_BLOCK;
public static Block CHEESE_ORE;
public static Block CHEESE_ORE_NETHER;
public static Block CHEESE_ORE_END;
public static Block QUICK_CHEESE;
public static Block COMPLIMENT_MACHINE;
public static Block BELGIUM_FLAG;
public static Block CHEESE_WORKBENCH;

public CheeseBlocks() {
	init();
	register();
}

public static void init() {
	CHEESE_ORE = new CheeseOre().setCreativeTab(DeGeweldigeMod.tabCheeseStuff).setHardness(2F);
	CHEESE_ORE_NETHER = new CheeseOreNether().setCreativeTab(DeGeweldigeMod.tabCheeseStuff).setHardness(2F);
	CHEESE_ORE_END = new CheeseOreEnd().setCreativeTab(DeGeweldigeMod.tabCheeseStuff).setHardness(2F);
	CHEESE_BLOCK = new Block(Material.ROCK).setCreativeTab(DeGeweldigeMod.tabCheeseStuff).setHardness(3F);
	QUICK_CHEESE = new QuickCheese().setHardness(4F);
	COMPLIMENT_MACHINE = new ComplimentsMachine(Material.PISTON).setCreativeTab(DeGeweldigeMod.tabCheeseStuff).setHardness(3F);
	BELGIUM_FLAG = new BelgiumFlag().setCreativeTab(DeGeweldigeMod.tabCheeseStuff).setHardness(2F);
	CHEESE_WORKBENCH = new CheeseWorkbench().setCreativeTab(DeGeweldigeMod.tabCheeseStuff).setHardness(2F).setUnlocalizedName("cheese_crafting_table");

	CheeseUtils.setNames(CHEESE_ORE, "cheese_ore");
	CheeseUtils.setNames(CHEESE_ORE_NETHER, "cheese_ore_nether");
	CheeseUtils.setNames(CHEESE_ORE_END, "cheese_ore_end");
	CheeseUtils.setNames(CHEESE_BLOCK, "cheese_block");
	CheeseUtils.setNames(QUICK_CHEESE, "quick_cheese");
	CheeseUtils.setNames(COMPLIMENT_MACHINE, "compliment_machine");
	CheeseUtils.setNames(BELGIUM_FLAG, "belgium_flag");
	CheeseUtils.setNames(CHEESE_WORKBENCH, "cheese_crafting_table");
}	

public void register() {
	this.registerBlock(CHEESE_ORE);
	this.registerBlock(CHEESE_ORE_NETHER);
	this.registerBlock(CHEESE_ORE_END);
	this.registerBlock(CHEESE_BLOCK);
	this.registerBlock(QUICK_CHEESE);
	this.registerBlock(COMPLIMENT_MACHINE);
	this.registerBlock(BELGIUM_FLAG);
	this.registerBlock(CHEESE_WORKBENCH);
}	

private void registerBlock(Block block) {
	GameRegistry.register(block);
	GameRegistry.register(new ItemBlock(block).setUnlocalizedName(block.getUnlocalizedName()).setRegistryName(block.getRegistryName()));
}

}

My custom crafting table class:

public class CheeseWorkbench extends Block {
protected CheeseWorkbench() {
        super(Material.WOOD);
    }

    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
        if (worldIn.isRemote) {
            return true;
        } else {
            playerIn.displayGui(new CheeseWorkbench.InterfaceCraftingTable(worldIn, pos));
            playerIn.addStat(StatList.CRAFTING_TABLE_INTERACTION);
            return true;
        }
    }

    public static class InterfaceCraftingTable implements IInteractionObject {
    	private final World world;
    	private final BlockPos position;
    	
    	public InterfaceCraftingTable(World worldIn, BlockPos pos) {
    		this.world = worldIn;
    		this.position = pos;
    	}
    	
    	public String getName() {
    		return null;
    	}
    	
    	public boolean hasCustomName() {
    		return false;
    	}
    	
    	public ITextComponent getDisplayName() {
    		return new TextComponentTranslation(CheeseBlocks.CHEESE_WORKBENCH.getUnlocalizedName() + ".name", new Object[0]);
    	}
    	
    	public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) {
    		return new ContainerWorkbench(playerInventory, this.world, this.position);
    	}

    	public String getGuiID() {
    		return "minecraft:crafting_table";
    	}
    }
}

Posted

Also, my ClientProxy:

public class ClientProxy extends CommonProxy {

public void registerModels() {
	registerItemModel(CheeseItems.CHEESE, 0);
	registerItemModel(CheeseItems.CHEESE_COOKED, 0);
	registerItemModel(CheeseItems.BREAD_CHEESE, 0);
	registerItemModel(CheeseItems.CHEESE_APPLE, 0);
	registerItemModel(CheeseItems.CHEESE_BUCKET, 0);
	registerItemModel(CheeseItems.CHEESE_INGOT, 0);

	registerItemModel(CheeseItems.CHEESE_SWORD, 0);
	registerItemModel(CheeseItems.CHEESE_PICKAXE, 0);
	registerItemModel(CheeseItems.CHEESE_AXE, 0);
	registerItemModel(CheeseItems.CHEESE_SHOVEL, 0);
	registerItemModel(CheeseItems.CHEESE_HOE, 0);
	registerItemModel(CheeseItems.CHEESE_FLY_STICK, 0);

	registerItemModel(CheeseItems.CHEESE_HELMET, 0);
	registerItemModel(CheeseItems.CHEESE_CHESTPLATE, 0);
	registerItemModel(CheeseItems.CHEESE_LEGGINGS, 0);
	registerItemModel(CheeseItems.CHEESE_BOOTS, 0);

	registerBlockModel(CheeseBlocks.CHEESE_ORE, 0);
	registerBlockModel(CheeseBlocks.CHEESE_ORE_NETHER, 0);
	registerBlockModel(CheeseBlocks.CHEESE_ORE_END, 0);
	registerBlockModel(CheeseBlocks.CHEESE_BLOCK, 0);
	registerBlockModel(CheeseBlocks.QUICK_CHEESE, 0);
	registerBlockModel(CheeseBlocks.COMPLIMENT_MACHINE, 0);
	registerBlockModel(CheeseBlocks.BELGIUM_FLAG, 0);
	registerBlockModel(CheeseBlocks.CHEESE_WORKBENCH, 0);
}

public void renderEntities() {
	RenderingRegistry.registerEntityRenderingHandler(EntityCheeseCow.class, new RenderingHandlerCheeseCow());
}

private void registerItemModel(Item item, int meta) {
	ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(item.getRegistryName(), "inventory"));
}

private void registerBlockModel(Block block, int meta) {
	ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), meta, new ModelResourceLocation(block.getRegistryName(), "inventory"));
}
}

Posted

isRemote does opposite of what you think (and initially anyone else). illogical, but rename probably won't happen.

switch that and work from there (i honestly can't tell what else is wrong).

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

    • Different problem now. https://paste.ee/p/iDo8lS35
    • I would like to have a BoP sapling drop from my block if it is also installed. I think I have done everything and I cannot pinpoint the problem, which is the error in the logs that appears when joining a world:   [Worker-Main-11/ERROR] [ne.mi.co.ForgeHooks/]: Couldn't parse element loot_tables:grasses:blocks/leaves_block com.google.gson.JsonSyntaxException: Expected name to be an item, was unknown string 'biomesoplenty:magic_sapling' My code:   LootItemConditions.CONDITIONS.register(modEventBus); public class LootItemConditions { public static final DeferredRegister<LootItemConditionType> CONDITIONS = DeferredRegister.create(Registries.LOOT_CONDITION_TYPE, Grasses.MOD_ID); public static final RegistryObject<LootItemConditionType> IS_MOD_LOADED = CONDITIONS.register("is_mod_loaded", () -> new LootItemConditionType(new IsModLoaded.ConditionSerializer())); } public class IsModLoaded implements LootItemCondition { private final boolean exists; private final String modID; public IsModLoaded(String modID) { this.exists = ModList.get().isLoaded(modID); this.modID = modID; } @Override public LootItemConditionType getType() { return LootItemConditions.IS_MOD_LOADED.get(); } @Override public boolean test(LootContext context) { return this.exists; } public static LootItemCondition.Builder builder(String modid) { return () -> new IsModLoaded(modid); } public static class ConditionSerializer implements Serializer<IsModLoaded> { @Override public void serialize(JsonObject json, IsModLoaded instance, JsonSerializationContext ctx) { json.addProperty("modid", instance.modID); } @Override public IsModLoaded deserialize(JsonObject json, JsonDeserializationContext ctx) { return new IsModLoaded(GsonHelper.getAsString(json, "modid")); } } } protected LootTable.Builder createLeavesDropsWithModIDCheck(Block selfBlock, Item sapling, Property<?>[] properties, String modIDToCheck, float... chances) { CopyBlockState.Builder blockStateCopyBuilder = CopyBlockState.copyState(selfBlock); for(Property<?> property : properties) { blockStateCopyBuilder.copy(property); } return LootTable.lootTable() .withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)) .add(LootItem.lootTableItem(selfBlock) .when(HAS_SHEARS_OR_SILK_TOUCH) .apply(blockStateCopyBuilder))) .withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)) .add(this.applyExplosionCondition(selfBlock, LootItem.lootTableItem(sapling)) .when(IsModLoaded.builder(modIDToCheck))) .when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.BLOCK_FORTUNE, chances)) .when(HAS_NO_SHEARS_OR_SILK_TOUCH)) .withPool(LootPool.lootPool().name("sticks").setRolls(ConstantValue.exactly(1.0F)) .add(this.applyExplosionDecay(selfBlock, LootItem.lootTableItem(Items.STICK). apply(SetItemCountFunction.setCount(UniformGenerator.between(1.0F, 2.0F)))) .when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.BLOCK_FORTUNE, NORMAL_LEAVES_STICK_CHANCES)) .when(HAS_NO_SHEARS_OR_SILK_TOUCH))); } I don't know. Am I making a mistake somewhere? Am I forgetting something? Should there be something else?
  • Topics

×
×
  • Create New...

Important Information

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