Jump to content

EnumRailDirection issue


UltraTechX

Recommended Posts

I have this basic class with EnumRailDirection:

 

package ultratechx.autotrains;

import net.minecraft.block.Block;
import net.minecraft.block.BlockRail;
import net.minecraft.block.BlockRailBase;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.IStringSerializable;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class railControlBlock extends BlockRail implements ITileEntityProvider {

public static final PropertyEnum PART = PropertyEnum.create("part", EnumPartType.class);
public static final PropertyEnum SHAPE = PropertyEnum.create("shape", BlockRailBase.EnumRailDirection.class);

private static String name = "railControlBlock";
private int part;

    public railControlBlock(int pnum) {
    	
        super();
        GameRegistry.registerTileEntity(railControl.class, name);
        if(pnum == 0) {
        	setDefaultState(this.blockState.getBaseState().withProperty(PART, EnumPartType.MIDDLE).withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH));
        	this.part = 0;
        }else if(pnum == 1){
        	setDefaultState(this.blockState.getBaseState().withProperty(PART, EnumPartType.LEFT).withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH));
        	this.part = 1;
        }else if(pnum == 2){
        	setDefaultState(this.blockState.getBaseState().withProperty(PART, EnumPartType.RIGHT).withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH));
        	this.part = 2;
        }
        
        GameRegistry.registerBlock(this, name);
        this.setCreativeTab(CreativeTabs.tabMisc);
        this.setUnlocalizedName(name);
        this.setHardness(2.0f);
        setBlockBounds();
        this.setResistance(6.0f);
        this.setHarvestLevel("pickaxe", 2);
        this.isBlockContainer = true;
        
    }
    
    @Override
    public String toString() {
        return getName();
    }
    
    
    
  

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



public static String getName(){
    	return name;
    }


  
  @SideOnly(Side.CLIENT)
  public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos)
  {
    setBlockBoundsBasedOnState(worldIn, pos);
    return super.getSelectedBoundingBox(worldIn, pos);
  }

public IProperty getShapeProperty()
  {
    return SHAPE;
  }

public IProperty getPartProperty()
  {
    return PART;
  }


  
  public IBlockState getStateFromMeta(int meta)
  {
    return getDefaultState().withProperty(PART, EnumPartType.byMetadata(meta)).withProperty(SHAPE, BlockRailBase.EnumRailDirection.byMetadata(meta));
  }
  
  @Override
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
    {
        
            setBlockBounds();
        
    }
  
  
  private void setBlockBounds()
  {
	  setBlockBounds(0F, 0.0F, 0F, 1F, 0.125F, 1F);
  }
  
  public int getMetaFromState(IBlockState state)
  {
    return ((BlockRailBase.EnumRailDirection)state.getValue(SHAPE)).getMetadata();
  }
  
  @Override
  public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos){
	  if(this.part == 2){
		  return state.withProperty(PART, EnumPartType.RIGHT);
	  }else if(this.part == 1){
		  return state.withProperty(PART, EnumPartType.LEFT);
	  }else{
		  return state.withProperty(PART, EnumPartType.MIDDLE);
	  }
	  
  }
  
  protected BlockState createBlockState()
  {
    return new BlockState(this, new IProperty[] { PART, SHAPE });
  }
  
  
  
  public boolean isOpaqueCube()
  {
  return false;
  }
  
  /**
  * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
  */

  public boolean renderAsNormalBlock()
  {
  return false;
  }

  public int getRenderBlockPass()
  {
  return 1;
  }
  
  public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
  {
	  updateMultiBlockStructure(worldIn, pos.getX(), pos.getY(), pos.getZ());
  }
  
  public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state){
	  updateMultiBlockStructure(worldIn, pos.getX(), pos.getY(), pos.getZ());
  }
  
  public void updateMultiBlockStructure(World world, int x, int y, int z){
	  isMultiBlockStructure(world, x, y, z);
  }
  
  public boolean isMultiBlockStructure(World world, int x1, int y1, int z1){
	  boolean mStructure = false;
	  boolean currentCheckStructure = true;
	  
	  for(int x3 = 0; x3 < 3; x3++){
		  for(int z3 = 0; z3 < 3; z3++){
			  BlockPos neighbourPos = new BlockPos(x1 - x3, y1, z1 - z3);
			  IBlockState neighbourState = world.getBlockState(neighbourPos);
			  Block neighbourBlock = neighbourState.getBlock();
			  if(currentCheckStructure && neighbourBlock != AutoTrains.railControl){
				  System.out.println("this is not a multi block structure");
				  currentCheckStructure = false;
			  }else{
				  System.out.println("this is a multi block structure");
			  }
		  }
	  }
	  
	  return false;
  }
  
  
  protected void onNeighborChangedInternal(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
  {
    //whenever the blocks around it change
  }
  
  public static enum EnumPartType
    implements IStringSerializable
  {
    MIDDLE(0, "middle"),  
    LEFT(1, "left"), 
    RIGHT(2, "right");
	  
	private static final EnumPartType[] META_LOOKUP = new EnumPartType[values().length];

	private final int meta;
    
    private final String name;
    
    private EnumPartType(int meta, String name)
        {
            this.meta = meta;
            this.name = name;
        }

        public int getMetadata()
        {
            return this.meta;
        }

        public String toString()
        {
            return this.name;
        }
    public String getName()
    {
      return this.name;
    }
    
    public static EnumPartType byMetadata(int meta)
        {
            if (meta < 0 || meta >= META_LOOKUP.length)
            {
                meta = 0;
            }

            return META_LOOKUP[meta];
        }
    
    static
        {
            EnumPartType[] var0 = values();
            int var1 = var0.length;

            for (int var2 = 0; var2 < var1; ++var2)
            {
                EnumPartType var3 = var0[var2];
                META_LOOKUP[var3.getMetadata()] = var3;
            }
        }
  }
  
}

 

 

but it wont turn when it should like a normal rail, any ideas?

I'm working on something big!  As long as there arent alot of big issues... [D

Link to comment
Share on other sites

nevermind, i fixed it by adding this into my onBlockAdded method after taking a look at the BlockRailBase class:

 

if (!worldIn.isRemote)

    {

            state = this.func_176564_a(worldIn, pos, state, true);

}

I'm working on something big!  As long as there arent alot of big issues... [D

Link to comment
Share on other sites

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

    • Hi, I want to make a client-only mod, everything is ok, but when I use shaders, none of the textures rendered in RenderLevelStageEvent nor the crow entity model are rendered, I want them to be visible, because it's a horror themed mod Here is how i render the crow model in the CrowEntityRenderer<CrowEntity>, by the time i use this method, i know is not the right method but i don't think this is the cause of the problem, the renderType i'm using is entityCutout @Override public void render(CrowEntity p_entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { super.render(p_entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); ClientEventHandler.getClient().crow.renderToBuffer(poseStack, bufferSource.getBuffer(ClientEventHandler.getClient().crow .renderType(TEXTURE)), packedLight, OverlayTexture.NO_OVERLAY, Utils.rgb(255, 255, 255)); } Here renderLevelStage @Override public void renderWorld(RenderLevelStageEvent e) { horrorEvents.draw(e); } Here is how i render every event public void draw(RenderLevelStageEvent e) { for (HorrorEvent event : currentHorrorEvents) { event.tick(e.getPartialTick()); event.draw(e); } } Here is how i render the crow model on the event @Override public void draw(RenderLevelStageEvent e) { if(e.getStage() == RenderLevelStageEvent.Stage.AFTER_ENTITIES) { float arcProgress = getArcProgress(0.25f); int alpha = (int) Mth.lerp(arcProgress, 0, 255); int packedLight = LevelRenderer.getLightColor(Minecraft.getInstance().level, blockPos); VertexConsumer builder = ClientEventHandler.bufferSource.getBuffer(crow); Crow<CreepyBirdHorrorEvent> model = ClientEventHandler .getClient().crow; model.setupAnim(this); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, packedLight, OverlayTexture.NO_OVERLAY, alpha); builder = ClientEventHandler.bufferSource.getBuffer(eyes); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, 15728880, OverlayTexture.NO_OVERLAY, alpha); } } How i render the model public static void renderModelInWorld(Model model, Vector3f pos, Vector3f offset, Camera camera, PoseStack matrix, VertexConsumer builder, int light, int overlay, int alpha) { matrix.pushPose(); Vec3 cameraPos = camera.getPosition(); double finalX = pos.x - cameraPos.x + offset.x; double finalY = pos.y - cameraPos.y + offset.y; double finalZ = pos.z - cameraPos.z + offset.z; matrix.pushPose(); matrix.translate(finalX, finalY, finalZ); matrix.mulPose(Axis.XP.rotationDegrees(180f)); model.renderToBuffer(matrix, builder, light, overlay, Utils .rgba(255, 255, 255, alpha)); matrix.popPose(); matrix.popPose(); } Thanks in advance
    • Here's the link: https://mclo.gs/7L5FibL Here's the link: https://mclo.gs/7L5FibL
    • Also the mod "Connector Extras" modifies Reach-entity-attributes and can cause fatal errors when combined with ValkrienSkies mod. Disable this mod and continue to use Syntra without it.
    • Hi everyone. I was trying modify the vanilla loot of the "short_grass" block, I would like it drops seeds and vegetal fiber (new item of my mod), but I don't found any guide or tutorial on internet. Somebody can help me?
    • On 1.20.1 use ValkrienSkies mod version 2.3.0 Beta 1. I had the same issues as you and it turns out the newer beta versions have tons of unresolved incompatibilities. If you change the version you will not be required to change the versions of eureka or any other additions unless prompted at startup. This will resolve Reach-entity-attributes error sound related error and cowardly errors.
  • Topics

×
×
  • Create New...

Important Information

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