Jump to content

Recommended Posts

Posted
  On 12/9/2021 at 1:48 PM, diesieben07 said:

SHow your code.

Expand  
package ocean.chinacraft.common.block.decoration;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.FourWayBlock;
import net.minecraft.block.PaneBlock;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.StateContainer;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import ocean.chinacraft.common.block.properties.PropertiesMisc;

/**
 * 木窗格
 *
 * @author zhang
 * @since 2021/12/9
 */
public class WoodWindow extends FourWayBlock {

    public WoodWindow() {
        super(1.0F, 1.0F, 16.0F, 16.0F, 16.0F, PropertiesMisc.defaultWindow());
        this.registerDefaultState(this.stateDefinition.any().setValue(NORTH, Boolean.FALSE).setValue(EAST,
                Boolean.FALSE).setValue(SOUTH, Boolean.FALSE).setValue(WEST,
                Boolean.FALSE).setValue(WATERLOGGED, Boolean.FALSE));
    }

    @Override
    public BlockState getStateForPlacement(BlockItemUseContext context) {
        IBlockReader iblockreader = context.getLevel();
        BlockPos blockpos = context.getClickedPos();
        FluidState fluidstate = context.getLevel().getFluidState(context.getClickedPos());
        BlockPos blockpos1 = blockpos.north();
        BlockPos blockpos2 = blockpos.south();
        BlockPos blockpos3 = blockpos.west();
        BlockPos blockpos4 = blockpos.east();
        BlockState blockstate = iblockreader.getBlockState(blockpos1);
        BlockState blockstate1 = iblockreader.getBlockState(blockpos2);
        BlockState blockstate2 = iblockreader.getBlockState(blockpos3);
        BlockState blockstate3 = iblockreader.getBlockState(blockpos4);
        return this.defaultBlockState().setValue(NORTH, this.attachsTo(blockstate,
                blockstate.isFaceSturdy(iblockreader, blockpos1, Direction.SOUTH))).setValue(SOUTH,
                this.attachsTo(blockstate1, blockstate1.isFaceSturdy(iblockreader, blockpos2,
                        Direction.NORTH))).setValue(WEST, this.attachsTo(blockstate2,
                blockstate2.isFaceSturdy(iblockreader, blockpos3, Direction.EAST))).setValue(EAST,
                this.attachsTo(blockstate3, blockstate3.isFaceSturdy(iblockreader, blockpos4,
                        Direction.WEST))).setValue(WATERLOGGED, fluidstate.getType() == Fluids.WATER);
    }

    @Override
    public BlockState updateShape(BlockState p_196271_1_, Direction p_196271_2_, BlockState p_196271_3_,
                                  IWorld p_196271_4_, BlockPos p_196271_5_, BlockPos p_196271_6_) {
        if (p_196271_1_.getValue(WATERLOGGED)) {
            p_196271_4_.getLiquidTicks().scheduleTick(p_196271_5_, Fluids.WATER,
                    Fluids.WATER.getTickDelay(p_196271_4_));
        }

        return p_196271_2_.getAxis().isHorizontal() ? p_196271_1_.setValue(PROPERTY_BY_DIRECTION.get(p_196271_2_),
                Boolean.valueOf(this.attachsTo(p_196271_3_, p_196271_3_.isFaceSturdy(p_196271_4_, p_196271_6_,
                        p_196271_2_.getOpposite())))) : super.updateShape(p_196271_1_, p_196271_2_, p_196271_3_,
                p_196271_4_, p_196271_5_, p_196271_6_);
    }

    @Override
    public VoxelShape getVisualShape(BlockState p_230322_1_, IBlockReader p_230322_2_, BlockPos p_230322_3_,
                                     ISelectionContext p_230322_4_) {
        return VoxelShapes.empty();
    }

    @Override
    @OnlyIn(Dist.CLIENT)
    public boolean skipRendering(BlockState p_200122_1_, BlockState p_200122_2_, Direction p_200122_3_) {
        if (p_200122_2_.is(this)) {
            if (!p_200122_3_.getAxis().isHorizontal()) {
                return true;
            }

            if (p_200122_1_.getValue(PROPERTY_BY_DIRECTION.get(p_200122_3_)) && p_200122_2_.getValue(PROPERTY_BY_DIRECTION.get(p_200122_3_.getOpposite()))) {
                return true;
            }
        }

        return super.skipRendering(p_200122_1_, p_200122_2_, p_200122_3_);
    }

    public final boolean attachsTo(BlockState p_220112_1_, boolean p_220112_2_) {
        Block block = p_220112_1_.getBlock();
        return !isExceptionForConnection(block) && p_220112_2_ || block instanceof PaneBlock || block.is(BlockTags.WALLS);
    }

    @Override
    protected void createBlockStateDefinition(StateContainer.Builder<Block, BlockState> p_206840_1_) {
        p_206840_1_.add(NORTH, EAST, WEST, SOUTH, WATERLOGGED);
    }
}


status:


{
  "multipart": [
    {
      "apply": {
        "model": "chinacraft:block/wood_window_post"
      }
    },
    {
      "when": {
        "north": "true"
      },
      "apply": {
        "model": "chinacraft:block/wood_window_side"
      }
    },
    {
      "when": {
        "east": "true"
      },
      "apply": {
        "model": "chinacraft:block/wood_window_side",
        "y": 90
      }
    },
    {
      "when": {
        "south": "true"
      },
      "apply": {
        "model": "chinacraft:block/wood_window_side_alt"
      }
    },
    {
      "when": {
        "west": "true"
      },
      "apply": {
        "model": "chinacraft:block/wood_window_side_alt",
        "y": 90
      }
    },
    {
      "when": {
        "north": "false"
      },
      "apply": {
        "model": "chinacraft:block/wood_window_noside"
      }
    },
    {
      "when": {
        "east": "false"
      },
      "apply": {
        "model": "chinacraft:block/wood_window_noside_alt"
      }
    },
    {
      "when": {
        "south": "false"
      },
      "apply": {
        "model": "chinacraft:block/wood_window_noside_alt",
        "y": 90
      }
    },
    {
      "when": {
        "west": "false"
      },
      "apply": {
        "model": "chinacraft:block/wood_window_noside",
        "y": 270
      }
    }
  ]
}

 

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

    • Managed to solve the issue myself. Solved by a fresh modpack instance.
    • Hello, so straight to the problem. Today i wanted to startup Enigmatica as usual and it just wont startup. Last night everything worked fine, i didnt even turn off my pc. Crash log: https://mclo.gs/GJ6Kcy1
    • Rubidium and Embeddium are versions of the same mod, you can only have one. I believe Embeddium is the one that's actively maintained.
    • Hello, New to modding, but have a solid CS foundation. I've created multiple custom BlockEntities that all have the same issue, which is that the inventory only updates on right click (overriding the useItemOn method). I've seen multiple posts on here outlining a similar issue to mine, but I've already implemented the solution of: overriding the correct methods in the BlockEntity class and calling setChanged(). I've tried every different place for setChanged() to no success. I'm wondering if I'm missing something else or if there was some change to sending data to the client in 1.21.5? Or will I have to use a custom packet sender? Here is the code for one of my BlockEntity classes with a single inventory slot: public class MyCustomBlockEntity extends BlockEntity { public final ItemStackHandler inventory = new ItemStackHandler(1) { @Override protected int getStackLimit(int slot, @NotNull ItemStack stack) { return 1; } @Override protected void onContentsChanged(int slot) { setChanged(); if (!level.isClientSide()) { level.setBlockAndUpdate(getBlockPos(), getBlockState()); } } }; public MyCustomBlockEntity(BlockPos pPos, BlockState pBlockState) { super(ModBlockEntities.MY_CUSTOM_BE.get(), pPos, pBlockState); } public void clearContents() { inventory.setStackInSlot(0, ItemStack.EMPTY); } public void dropItem() { SimpleContainer inv = new SimpleContainer(inventory.getSlots()); inv.setItem(0, inventory.getStackInSlot(0)); Containers.dropContents(this.level, this.worldPosition, inv); } @Override public void setRemoved() { dropItem(); super.setRemoved(); } @Override protected void saveAdditional(CompoundTag pTag, HolderLookup.Provider pRegistries) { super.saveAdditional(pTag, pRegistries); pTag.put("inventory", inventory.serializeNBT(pRegistries)); } @Override protected void loadAdditional(CompoundTag pTag, HolderLookup.Provider pRegistries) { super.loadAdditional(pTag, pRegistries); inventory.deserializeNBT(pRegistries, pTag.getCompound("inventory").get()); } @Override public Packet<ClientGamePacketListener> getUpdatePacket() { return ClientboundBlockEntityDataPacket.create(this); } @Override public CompoundTag getUpdateTag(HolderLookup.Provider pRegistries) { return saveWithoutMetadata(pRegistries); } } Mostly encountering the issue when calling the clearContents() method anywhere outside of useItemOn() in the Block class. I've also tried overriding both the handleUpdateTag() and onDataPacket() methods, calling their super along with loadAdditional(), but neither changed the outcome. Thanks in advance for any replies.
    • Hi all! I’m working on a Jurassic Park-themed mod for Minecraft 1.20.1, aiming to include dinosaurs, fossils, DNA extraction, and cool machines. This is a free project, mainly passion-driven, and I’ll give full credit to everyone involved. this is the perfect opportunity for beginners of modeling and coding. This project will give you experience and a creative freedom If you love dinosaurs and Minecraft modding, hit me up! Thanks! Add Me ogfrost. <--- Discord
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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