Jump to content

Recommended Posts

Posted

So as kinda given by the title, I'm trying to create a custom machine. To be more specific, a machine like a furnace but instead of cooking items, it combines 2 items into one - includes 2 of the same item (actually would like this to be more prioritised over 2 different items). It will also has 1 fuel slot where redstone dust/blocks are used to power it. I have looked up tutorials on custom machines; but they all pretty much involve smelting like a furnace, which I'm not trying to do. I feel like before I finish, I must mention that this is a custom block model machine and not one like a furnace where it just has different textures on the sides. I would also ideally like the fire cooking animation to be different. I believe I have most of the code done for the block itself; but I really need help on the actual functionality of this block. Detailed instructions on what each method would be highly appreciated, as I don't want just code that I don't understand and have no idea how to customise to make different machines.

Here's my code:

(Block Machine class)

package com.distinctsoul.soulforgery.blocks.machines;

import java.util.Random;

import com.distinctsoul.soulforgery.Main;
import com.distinctsoul.soulforgery.blocks.BlockBase;
import com.distinctsoul.soulforgery.init.ModBlocks;
import com.distinctsoul.soulforgery.util.Reference;

import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;

public class BlockShardFuser extends BlockBase implements ITileEntityProvider {
	
	public static final PropertyDirection FACING = BlockHorizontal.FACING;
	
	public BlockShardFuser(String name, Material material) {
		super(name, material);
		this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
		setSoundType(SoundType.STONE);
		setHardness(3.0F);
		setResistance(20.0F);
		setHarvestLevel("pickaxe", 2);
		// setLightLevel(0.1F);
		// setLightOpacity(1);
		// setBlockUnbreakable();
	}
	
	@Override
	public Item getItemDropped(IBlockState state, Random rand, int fortune) {
		return Item.getItemFromBlock(ModBlocks.SHARD_FUSER);
	}
	
	@Override
	public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
		return new ItemStack(ModBlocks.SHARD_FUSER);
	}
	
	public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
		worldIn.setBlockState(pos, this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing()), 2);
	}
	
	public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY,
			float hitZ, int meta, EntityLivingBase placer) {
		return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
	}
	
	public static final AxisAlignedBB SHARD_FUSER_AABB = new AxisAlignedBB(0, 0, 0, 1, 1, 1);
	
	@Override
	public boolean isOpaqueCube(IBlockState state) {
		return false;
	}
	
	@Override
	public boolean isFullCube(IBlockState state) {
		return true;
	}
	
	@Override
	public EnumBlockRenderType getRenderType(IBlockState iBlockState) {
		return EnumBlockRenderType.MODEL;
	}
	
	@Override
	public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
		return SHARD_FUSER_AABB;
	}
	
	public IBlockState getStateFromMeta(int meta) {
		EnumFacing facing = EnumFacing.getHorizontal(meta);
		return this.getDefaultState().withProperty(FACING, facing);
	}
	
	public int getMetaFromState(IBlockState state) {
		EnumFacing facing = (EnumFacing)state.getValue(FACING);
		
		int facingbits = facing.getHorizontalIndex();
		return facingbits;
	}
	
	@Override
	protected BlockStateContainer createBlockState() {
		return new BlockStateContainer(this, new IProperty[] { FACING });
	}

	@Override
	public TileEntity createNewTileEntity(World worldIn, int meta) {
		return null;
	}
	
}

 

(BlockState json)

{
    "variants": {
        "facing=north": { "model": "soulforgery:shard_fuser" },
        "facing=south": { "model": "soulforgery:shard_fuser", "y": 180 },
        "facing=east": { "model": "soulforgery:shard_fuser", "y": 90 },
        "facing=west": { "model": "soulforgery:shard_fuser", "y": 270 }
    }
}

 

Any help would be very appreciated.

Posted

Instead of quoting everything that’s wrong, I’m just going to link https://gist.github.com/Cadiboo/fbea89dc95ebbdc58d118f5350b7ba93. Please read it. Descriptions of most of the methods can be found in their javadocs. If those are lacking, you can find out what the method does by finding the usages of it.

 

Im not sure if it’s mentioned in the file I linked, but don’t use ITileEntityProvider, it’s legacy vanilla code and Forge has a better replacement. Simply override hasTileEntity(IBlockState) and createTileEntity(IBlockState) in your block class. To answer your question, all functionality outside of your block just sitting there is implemented through a TileEntity (usually a Tickable one)

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)

Posted (edited)

Loop over all your items and call the same code you would have in IHasModel. You subscribe to the registry event in the relevant EventSubscriber. Models should go in the client-only event subscriber, Object registration should go in the common/normal event subscriber.

Extract to a helper method means moving the same code that you call a lot into 1 helper method

Edited by Cadiboo

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)

Posted

Short version:

@SubscribeEvent
public void registerModelsWithoutIHasModelLikeAGoodBoi(ModelRegistryEvent event) {
	modItems.forEach(item -> {
		ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
	});
}

Something like that.

Basically loop through all your items and do what you normally do with IHasModel.

 

Cadiboo's example mod shows how to register stuff with good practices (the complete version); you might want to check that out.

The link is probably somewhere in his signature.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

  • 3 weeks later...
Posted
1 minute ago, Distinct Soul said:

I now get an error for 'ForgeRegistries', an error for the 'getNameSpace' on the 'onTextureStitchEvent' constructor, and an error for 'getPath' right after that.

What are the errors exactly? You are probably using outdated mappings as my mod was built for the latest mappings.

getResourceDomain -> getNameSpace

getResourcePath -> getPath

onTextureStitchEvent isn’t a class, it’s a method so it can’t have a constructor.

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)

Posted

Ah. I should probably update the forge that I'm using thinking about it. But also, are these new mappings still found on the most recommended release for Forge on 1.12? Or only later versions?

Not to mention, 'ForgeDirectories' comes up with an error stating to import it. But when I do, I then get an error for MOD_ID.

Posted
Just now, Distinct Soul said:

But also, are these new mappings still found on the most recommended release for Forge on 1.12? Or only later versions?

Mappings are separate from Forge

 

MCP (Mod Coder Pack) Mappings are what Forge uses to deobfuscate minecraft’s code and turn it into something human-readable.

These mapping names are provided by the community and can change, so it’s relatively important to keep them up to date. You can find a list of mappings here. Simply copy the name/date of the release and put it into your build.gradle file in the minecraftblock.

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)

Posted

You’ll need to run setupDecompWorkspace again (only on 1.12.2 & below) and then refresh the Gradle Project

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)

Posted

Under gradle tasks

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)

Posted

What IDE do you use? In IntelliJ the gradle tasks and the refresh Gradle Project button are in the gradle pane in the right sidebar. In eclipse I have no idea where it is, but you can use the command line to run gradlew setupDecompWorkspace

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)

Posted
8 hours ago, Cadiboo said:

What IDE do you use?

Did you rerun the appropriate setup tasks for your IDE & refresh the Gradle Project?

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)

Posted
On 5/3/2019 at 1:09 AM, Distinct Soul said:

CreativeTabs

ItemGroup

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)

Posted

1. Show your code.

2. Use your IDE to figure out what methods changed and the replacement for them.

3. Do you know Java?

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted
On 5/3/2019 at 1:09 AM, Distinct Soul said:

Well I now got that working; but now almost all my classes have errors. Probably because of the outdated things I'm using. For example: CreativeTabs has an error.

 

On 5/4/2019 at 2:10 PM, Cadiboo said:

ItemGroup

I was assuming that you had updated to 1.13. CreativeTabs were renamed to ItemGroups in 1.13.

 

On 5/6/2019 at 3:27 AM, Distinct Soul said:

I also now have an error for setUnlocalizedName after the mappings update.

 MOD_ID also still has an error.

Saying “an error” doesn’t really give us any information that we can use to help you.

*UnlocalisedName -> *TranslationKey

MOD_ID should be replaced by an import of your modid from your main class or constants class.

I think that I use static imports in my 1.12.2 example mod which is apparently hard for many people so I’ve stopped using them on the 1.13 branch

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)

Posted
10 hours ago, Distinct Soul said:

Also, by import of your modid, do you mean like Reference.MOD_ID?

yes

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)

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




×
×
  • Create New...

Important Information

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