Jump to content

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


Recommended Posts

Posted (edited)

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
Posted
// 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.

Posted

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);
    }
}

 

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

    • Honestly just want to play with my brother but LAN won't work for us so we have to try this.. Anyone?
    • Got modded, shit ton custom pack. Tried making a world, and it kicked me out saying that. Singelplayer. https://pastesio.com/crash-3317
    • I received an unexpected email claiming that a long-lost relative had left me a substantial inheritance $140,000 in cryptocurrency At first I was skeptical The message came with a lot of convincing documents legal jargon and even a supposed lawyer’s contact information They insisted everything was legitimate and the funds were waiting to be transferred All I needed to do they said was cover a few minor processing and transfer fees It seemed like a small price to pay for such a large windfall Against my better judgment I paid the fees Then more fees followed They kept assuring me the payout was right around the corner Weeks went by and the excuses kept coming Eventually it became clear this was a sophisticated scam The $140K inheritance was never real and I had been tricked into sending thousands of dollars to fraudsters embarrassed I started researching online and came across Byte phantom cyber services I was hesitant at first after all I had just been scammed But their website had positive reviews and they specialized in cryptocurrency fraud I reached out not expecting much To my surprise they responded quickly and professionally They were incredibly understanding and didn't make me feel foolish Their team walked me through the process step by step They used digital forensics and blockchain tracing techniques to track down the wallet addresses involved in the scam Within weeks they identified the fraudsters and began recovery efforts To my amazement Byte phantom cyber services recovered 100% of my lost funds Every cent I honestly couldn’t believe it They taught me how to recognize red flags avoid similar traps in the future and protect my digital identity I now feel empowered and informed not just lucky If you've been scammed or even suspect it don't stay silent Reach out to Byte phantom cyber services I got my money back
    • abro el juego pero al tocar un solo jugador me tira la de   [02:23:30] [Render thread/FATAL] [ne.mi.co.ForgeMod/]: Preparing crash report with UUID c3ff08d5-d285-458d-a3b5-fbba17743dff #@!@# Game crashed! Crash report saved to: #@!@# C:\juegos\Minecraft\instances\1.20.1 forge\.minecraft\crash-reports\crash-2025-05-02_02.23.30-client.txt Process exited with code -1 (0xffffffffffffffff). ¡Por favor, ten en cuenta que normalmente ni el código de salida ni su descripción son suficientes para diagnosticar problemas! Sube siempre el registro entero y no solo el código de salida.
    • So, First of I am new to modding so bare with me I am creating a 1.20.1 forge mod that needs Oculus/Embeddium as a dependancy because later on I need to add custom shaders in for lights and such. I am using ParchmentMC as I've heard its better because of namings of things but that doesn't seem to like it when I run it alongside Oculus (Its a very barebones script adding two blocks and an item, and tested it before I did this) The 4 errors I get when I run 'runClient' is Caused by: org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError: An unexpected critical error was encountered Caused by: org.spongepowered.asm.mixin.throwables.MixinApplyError: Mixin [mixins.oculus.json:texture.MixinAbstractTexture] from phase [DEFAULT] in config [mixins.oculus.json] FAILED during APPLY Caused by: org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException: Critical injection failure: @Inject annotation on iris$afterGenerateId could not find any targets matching 'Lnet/minecraft/client/renderer/texture/AbstractTexture;m_117963_()I' in net.minecraft.client.renderer.texture.AbstractTexture. Using refmap oculus-mixins-refmap.json [PREINJECT Applicator Phase -> mixins.oculus.json:texture.MixinAbstractTexture -> Prepare Injections ->  -> handler$zgm000$iris$afterGenerateId(Lorg/spongepowered/asm/mixin/injection/callback/CallbackInfoReturnable;)V -> Parse] And then a "Execution failed for task ':runClient'." error My dependancies are just these with latest forge for 1.20.1 implementation fg.deobf('curse.maven:oculus-581495:6020952') // Oculus for 1.20.1 - 1.8.0  implementation fg.deobf('curse.maven:embeddium-908741:5681725') // Embeddium for 1.20.1 - 0.3.31 I have tested these mods & forge in a different modpack alone and it works fine Any help is much appreciated!
  • Topics

×
×
  • Create New...

Important Information

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