Jump to content

[1.10.2][solved] Place block in world with rotation


KYPremco

Recommended Posts

I have a problem with my mod.

It's my first thing i try out but just can't find anywhere an aswer.

I want to save a structure that a player build in a 15x15x15 area and then rebuild it. this works for how far i am.

 

But when it's building it changes the direction of  the stairs, doors will be bugged and chests didn't test. Also my wood block went from spruce to normal.

 

I activate CreateStructure when i click on the top and startStructure on north side

 


When i use this on WithProperty it crashes and saying that the block (dispenser) doesnt have it

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

 

Code:

package com.kyproject.mynewmod.tileentity;
import net.minecraft.block.Block;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;

import java.util.ArrayList;

public class TileEntityBuilder extends TileEntity implements ITickable {

    public ArrayList<BlockPlace> blockStructure = new ArrayList<>();
    public ArrayList<BlockPlace> ORGIN = new ArrayList<>();

    ItemStackHandler inventory = new ItemStackHandler(9);
    boolean blockIsBuilding = false;
    int countBlocks = 0;
    int counter = 0;

    public static class BlockPlace {
        public Block block;
        public BlockPos pos;
        public IBlockState state;

        public BlockPlace(BlockPos pos, Block block, IBlockState state) {
            this.pos = pos;
            this.block = block;
            this.state = state;
        }
    }

    public void createStructure() {
        ArrayList<BlockPlace> blocks = new ArrayList<>();
        for(int x = 0;x < 15;x++) {
            for(int z = 1;z < 15;z++) {
                for(int y = 0;y < 15; y++) {
                    if(!worldObj.isAirBlock(pos.add(x,y,z))) {
                        blocks.add(new BlockPlace(pos.add(x,y,z),worldObj.getBlockState(pos.add(x,y,z)).getBlock(), worldObj.getBlockState(pos.add(x,y,z)).getBlock().getBlockState().getBaseState()));
                    }
                }
            }

        }
        ORGIN = blocks;
    }

    // Tried this but error occured
    public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);

    public void startStructure() {
        blockStructure.clear();
        blockStructure = (ArrayList<BlockPlace>) ORGIN.clone();
        blockIsBuilding = true;
        countBlocks = 0;
        counter = 0;
    }

    @Override
    public void update() {
        if(blockIsBuilding) {
            if(counter == 0) {
                if(blockStructure.size() == 0) {
                    blockIsBuilding = false;
                    countBlocks = 0;
                } else {
                    worldObj.setBlockState(blockStructure.get(0).pos, blockStructure.get(0).block.getDefaultState());
                    if(blockStructure.size()- 1 > 1) {
                        worldObj.setBlockState(blockStructure.get(blockStructure.size() - 1).pos, blockStructure.get(blockStructure.size() - 1).block.getDefaultState());
                        blockStructure.remove(blockStructure.size() - 1);
                    }
                    blockStructure.remove(0);
                    countBlocks++;
                }
                counter = 0;
            } else {
                counter++;
            }
            System.out.println(countBlocks);
        }


    }


    //Some other stuff
    @Override
    public void readFromNBT(NBTTagCompound compound) {
        super.readFromNBT(compound);
        inventory.deserializeNBT(compound.getCompoundTag("inventory"));
    }

    @Override
    public NBTTagCompound writeToNBT(NBTTagCompound compound) {
        compound.setTag("inventory", inventory.serializeNBT());
        return super.writeToNBT(compound);
    }

    @Override
    public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
        return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
    }

    @Override
    public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
        return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ? (T)inventory : super.getCapability(capability, facing);
    }
}

 

Edited by KYPremco
Link to comment
Share on other sites

// Tried this but error occured
    public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);

 

Of course it failed.

 

1) That property does not match BlockHorizontal.FACING, it's a completely different property. It just happens to have the same name and same values. Don't just create properties willy nilly, use a reference to the original. public static final PropertyDirection FACING = BlockHorizontal.FACING; magic.

2) Dispensers don't use horizontal facing, they use omnidirectional facing: that is, they can face UP and DOWN too.

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.

Link to comment
Share on other sites

Thank Draco that maded a little bit more clear.

I got it working but ended up doing it totally different.

 

If you still see something stupid please tell me.

 

package com.kyproject.mynewmod.tileentity;
import net.minecraft.block.BlockDirectional;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;

import java.util.ArrayList;

public class TileEntityBuilder extends TileEntity implements ITickable {

    public ArrayList<BlockPlace> blockStructure = new ArrayList<>();
    public ArrayList<BlockPlace> ORGIN = new ArrayList<>();

    ItemStackHandler inventory = new ItemStackHandler(9);
    boolean blockIsBuilding = false;
    int countBlocks = 0;
    int counter = 0;

    public static class BlockPlace {
        public BlockPos pos;
        public IBlockState state;

        public BlockPlace(BlockPos pos, IBlockState state) {
            this.pos = pos;
            this.state = state;
        }
    }

    public void createStructure() {
        ArrayList<BlockPlace> blocks = new ArrayList<>();
        for(int x = 0;x < 15;x++) {
            for(int z = 1;z < 15;z++) {
                for(int y = 0;y < 15; y++) {
                    if(!worldObj.isAirBlock(pos.add(x,y,z))) {
                        IBlockState state = worldObj.getBlockState(pos.add(x,y,z)).getActualState(worldObj, pos.add(x,y,z));
                        blocks.add(new BlockPlace(pos.add(x,y,z), state));
                    }
                }
            }

        }
        ORGIN = blocks;
    }

    public void startStructure() {
        blockStructure.clear();
        blockStructure = (ArrayList<BlockPlace>) ORGIN.clone();
        blockIsBuilding = true;
        countBlocks = 0;
        counter = 0;
    }

    @Override
    public void update() {
        if(blockIsBuilding) {
            if(counter == 0) {
                if(blockStructure.size() == 0) {
                    blockIsBuilding = false;
                    countBlocks = 0;
                } else {
                    worldObj.setBlockState(blockStructure.get(0).pos, blockStructure.get(0).state);

                    if(blockStructure.size() - 1 > 1) {
                        worldObj.setBlockState(blockStructure.get(blockStructure.size() - 1).pos, blockStructure.get(blockStructure.size() - 1).state);
                        blockStructure.remove(blockStructure.size() - 1);
                    }
                    blockStructure.remove(0);
                    countBlocks++;
                }
                counter = 0;
            } else {
                counter++;
            }
            System.out.println(countBlocks);
        }


    }

    @Override
    public void readFromNBT(NBTTagCompound compound) {
        super.readFromNBT(compound);
        inventory.deserializeNBT(compound.getCompoundTag("inventory"));
    }

    @Override
    public NBTTagCompound writeToNBT(NBTTagCompound compound) {
        compound.setTag("inventory", inventory.serializeNBT());
        return super.writeToNBT(compound);
    }

    @Override
    public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
        return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
    }

    @Override
    public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
        return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ? (T)inventory : super.getCapability(capability, facing);
    }
}

 

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



×
×
  • Create New...

Important Information

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