Jump to content

Recommended Posts

Posted

Hello all,

 

So I have this directional block in my mod, that accepts 3 types of capabilities (fluids, energy and items), however, on the front of the 'machine' I want the capabilities to return null, so it does not connect to any power handlers / fluid handlers / item handlers. I have most of it working, other than finding the side for it to return null on. I have tried this:

    	IBlockState state = this.world.getBlockState(this.getPos());
    	EnumFacing front = EnumFacing.getFront(state.getBlock().getMetaFromState(state));
    	if(facing != front) {
    		return this.storage;
    	}
		return null;

however, only 1 direction (north) actually returns null on the front.

 

How can I find the front of a directional block?

 

Thanks.

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Posted (edited)
.getMetaFromState(state)

No. Bad modder.

EnumFacing facing = state.getValue(BlockDirectional.FACING)
Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I changed my code:

    @Override
    public IEnergyStorage getEnergyStorage(EnumFacing facing) {
    	IBlockState state = this.world.getBlockState(this.getPos());
    	EnumFacing face = state.getValue(BlockDirectional.FACING);
    	if(facing != face) {
    		return this.storage;
    	}
		return null;
    }
    
    @Override
    public IFluidHandler getFluidHandler(EnumFacing facing) {
    	IBlockState state = this.world.getBlockState(this.getPos());
    	EnumFacing face = state.getValue(BlockDirectional.FACING);
    	if(facing != face) {
    		return this.fluidStorage;
    	}
		return null;
	}
    
    @Override
    public IItemHandler getItemHandler(EnumFacing facing) {
    	IBlockState state = this.world.getBlockState(this.getPos());
    	EnumFacing face = state.getValue(BlockDirectional.FACING);
    	if(facing != face) {
    		return this.slots;
    	}
		return null;
    }

However now it crashes:

java.lang.IllegalArgumentException: Cannot get property PropertyDirection{name=facing, clazz=class net.minecraft.util.EnumFacing, values=[down, up, north, south, west, east]} as it does not exist in BlockStateContainer{block=ce:void_infuser, properties=[facing]}
	at net.minecraft.block.state.BlockStateContainer$StateImplementation.getValue(BlockStateContainer.java:204)
	at com.unassigned.customenchants.blocks.tile.TileEntityVoidInfuser.getEnergyStorage(TileEntityVoidInfuser.java:167)
	at com.unassigned.customenchants.blocks.tile.base.TileEntityBase.getCapability(TileEntityBase.java:144)
	at com.unassigned.customenchants.blocks.tile.base.TileEntityBase.hasCapability(TileEntityBase.java:133)
	at cofh.thermaldynamics.duct.energy.DuctUnitEnergy.cacheTile(DuctUnitEnergy.java:115)
	at cofh.thermaldynamics.duct.energy.DuctUnitEnergy.cacheTile(DuctUnitEnergy.java:19)
	at cofh.thermaldynamics.duct.tiles.DuctUnit.loadSignificantCache(DuctUnit.java:157)
	at cofh.thermaldynamics.duct.energy.DuctUnitEnergy.handleTileSideUpdate(DuctUnitEnergy.java:88)
	at cofh.thermaldynamics.duct.tiles.DuctUnit.handleTileSideUpdate(DuctUnit.java:115)
	at cofh.thermaldynamics.duct.tiles.DuctUnit.updateAllSides(DuctUnit.java:231)
	at cofh.thermaldynamics.duct.tiles.TileGrid.onNeighborBlockChange(TileGrid.java:195)
	at cofh.thermaldynamics.duct.tiles.DuctUnit.onNeighborBlockChange(DuctUnit.java:283)
	at cofh.thermaldynamics.multiblock.MultiBlockFormer.checkMultiBlock(MultiBlockFormer.java:33)
	at cofh.thermaldynamics.multiblock.MultiBlockFormer.formGrid(MultiBlockFormer.java:23)
	at cofh.thermaldynamics.duct.tiles.DuctUnit.formGrid(DuctUnit.java:252)
	at cofh.thermaldynamics.duct.tiles.DuctUnit.singleTick(DuctUnit.java:349)
	at cofh.thermaldynamics.util.WorldGridList.tickEnd(WorldGridList.java:84)
	at cofh.thermaldynamics.util.TickHandler.tick(TickHandler.java:93)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_63_TickHandler_tick_WorldTickEvent.invoke(.dynamic)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179)
	at net.minecraftforge.fml.common.FMLCommonHandler.onPostWorldTick(FMLCommonHandler.java:273)
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:849)
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:741)
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:590)
	at java.lang.Thread.run(Unknown Source)

 

here is my block class:

Spoiler

package com.unassigned.customenchants.blocks;

import com.unassigned.customenchants.CustomEnchants;
import com.unassigned.customenchants.blocks.base.BlockTEBase;
import com.unassigned.customenchants.blocks.tile.TileEntityVoidInfuser;
import com.unassigned.customenchants.blocks.tile.inventory.gui.GuiHandler;

import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
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.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockVoidInfuser extends BlockTEBase {

    public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
	
	public BlockVoidInfuser(String name, Material materialIn) {
		super(name, materialIn);
		setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
	}
	
	@Override
	public boolean hasTileEntity(IBlockState state) {
		return true;
	}
		
	@Override
	public TileEntity createTileEntity(World world, IBlockState state) {
		return new TileEntityVoidInfuser();	
	}	

    @Override
    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9){
        if(!world.isRemote){
            TileEntityVoidInfuser tile = (TileEntityVoidInfuser)world.getTileEntity(pos);
            if(tile != null){
                player.openGui(CustomEnchants.instance, GuiHandler.GuiTypes.VOID_INFUSER.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
            }
            return true;
        }
        return true;
    }
    
    //V directional code V
    
    @Override
    public IBlockState getStateFromMeta(int meta) {
    	EnumFacing facing = EnumFacing.getHorizontal(meta);
    	return this.getDefaultState().withProperty(FACING, facing);
    }
    
    @Override
    public int getMetaFromState(IBlockState state) {
    	EnumFacing facing = (EnumFacing)state.getValue(FACING);
    	int face = facing.getHorizontalIndex();
    	return face;
    }
    
    @Override
    protected BlockStateContainer createBlockState() {
    	return new BlockStateContainer(this, new IProperty[] {FACING});
    }
    
    @Override
    public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY,
    		float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
    	EnumFacing enumfacing = (placer == null) ? EnumFacing.NORTH : EnumFacing.fromAngle(placer.rotationYaw);
    	
    	return this.getDefaultState().withProperty(FACING, enumfacing);
    }
    
    
}

 

 

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Posted (edited)

Ah, you're using the horizontal facing.

s/BlockDirectional.FACING/FACING

 

Also:

public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);

You can just use BlockHorizontal.FACING, rather than creating a new property.

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)

Okay I changed to use the property from BlockHorizontal, but I didn't understand what you meant by:

2 hours ago, Draco18s said:

Ah, you're using the horizontal facing.

 

As I still don't see the problem on why its crashing.

 

Okay, I picked up on what you meant, I changed your code to this:

    	EnumFacing face = state.getValue(BlockHorizontal.FACING);

However, the back of the machine is being ignored, not the front

Edited by Lambda

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

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

    • Back then there was a number which determined the tier of an item and block. If the block tier is lower or equal to the item number, the block would be mined. this however, has changed and now it goes by "needs_netherite_tool" which is fine, until you realized that some mods had items and blocks that exceeded these values. You can make you own "needs_mod_tool" but I feel that this is more limiting(and just more work) than before. So is there anyway to use something similar to the old tier system while also still being compatible with a lot of other mod tools?
    • Well, when I log in to the server, sometimes within an hour, sometimes within a minute, the server closes and informs me that there was a Ticking entity error. Below is the crash report
    • This forum is for Forge, not NeoForge. Please go to them for support.
    • Forge version: 55.0.0 Minecraft version: 1.21.5 Downloads: As this is the start of a new version, it is recommended that you check the downloads page and use the latest version to receive any bug fixes. Downloads page Intro: Good evening! Today, we have released our initial build of Forge 55.0 for Minecraft 1.21.5. 1.21.5 is the newest member of the 1.21 family of versions, which was released yesterday on March 25, 2025. As a reminder, the first minor (X.0) of a Forge version is a beta. Forge betas are marked as such on the bottom left of the title screen and are candidates for any breaking changes. Additionally, there are a couple of important things to note about this update, which I've made sure to mention in this post as well. Feel free to chat with us about bugs or these implementation changes on GitHub and in our Discord server. As always, we will continue to keep all versions of 1.21 and 1.20 in active support as covered by our tiered support policy. Cheers, happy modding, and good luck porting! Rendering Refactor For those who tuned in to Minecraft Live on March 22, 2025, you may already know that Mojang have announced their intention to bring their new Vibrant Visuals overhaul to Java in the future. They've taken the first steps toward this by refactoring how rendering pipelines and render types are handled internally. This has, in turn, made many of Forge's rendering APIs that have existed for years obsolete, as they (for the most part) can be done directly in vanilla. If there was a rendering API that was provided by Forge which you believe should be re-implemented, we're happy to discuss on GitHub through an issue or a pull request. Deprecation of weapon-like ToolActions In 1.21.5, Minecraft added new data components for defining the characteristics of weapons in data. This includes attack speed, block tags which define efficient blocks, and more. As such, we will begin marking our ToolActions solution for this as deprecated. ToolActions were originally added to address the problem of creating modded tools that needed to perform the same actions as vanilla tools. There are still a few tool actions that will continue to be used, such as the shears tool action for example. There are some existing Forge tool actions that are currently obsolete and have no effect given the way the new data components are implemented. We will continue to work on these deprecations and invite you to chat with us on GitHub or Discord if you have any questions.
  • Topics

×
×
  • Create New...

Important Information

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