Jump to content

[1.19] Copied FenceBlock, but North, South, East & West no setting correctly on placement


Jack709

Recommended Posts

Hello, Newbie here. I having an issue trying to make a fenceBlock and for some reason the North, South, East and West properties don't set correctly when i'm placing the item, therefore, the correct variant is not being used.

Here is a pick to illustrate what's happening. the 2 in the foreground should connect to each other like the one in the background, but NSEW are all false on the ones in the foreground.

directionIssue.png

Here is a link to the files, and keep in mind, I'm fairly new to Java and Minecraft modding :), it's the MediumYellowConduitDown

https://github.com/oneilljp-keyin/TrekFiles/blob/0ae07709966d916227f7b152b28db24e7037ad7b/src/main/java/tech/johnoneill/trekfiles/init/BlockInit.java

package tech.johnoneill.trekfiles.init;

import java.util.function.Function;

import com.google.common.base.Supplier;

import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FenceBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import tech.johnoneill.trekfiles.TrekFiles;
import tech.johnoneill.trekfiles.block.*;

public class BlockInit {
	public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS,
			TrekFiles.MOD_ID);

	public static final DeferredRegister<Item> ITEMS = ItemInit.ITEMS;

	public static final RegistryObject<Block> LARGE_YELLOW_CONDUIT_UP = register("large_yellow_conduit_up",
			() -> new LargeYellowConduitUp(BlockBehaviour.Properties.of(Material.HEAVY_METAL).sound(SoundType.METAL)),
			object -> () -> new BlockItem(object.get(), new Item.Properties().tab(TrekFiles.TREKFILES_TAB)));

	public static final RegistryObject<Block> LARGE_YELLOW_CONDUIT_DOWN = register("large_yellow_conduit_down",
			() -> new LargeYellowConduitDown(BlockBehaviour.Properties.of(Material.HEAVY_METAL).sound(SoundType.METAL)),
			object -> () -> new BlockItem(object.get(), new Item.Properties().tab(TrekFiles.TREKFILES_TAB)));

	public static final RegistryObject<FenceBlock> MEDIUM_YELLOW_CONDUIT_UP = register("medium_yellow_conduit_up",
			() -> new FenceBlock(BlockBehaviour.Properties.of(Material.HEAVY_METAL).sound(SoundType.METAL)),
			object -> () -> new BlockItem(object.get(), new Item.Properties().tab(TrekFiles.TREKFILES_TAB)));

	public static final RegistryObject<Block> MEDIUM_YELLOW_CONDUIT_DOWN = register("medium_yellow_conduit_down",
			() -> new MediumYellowConduitDown(BlockBehaviour.Properties.of(Material.METAL).sound(SoundType.METAL)),
			object -> () -> new BlockItem(object.get(), new Item.Properties().tab(TrekFiles.TREKFILES_TAB)));

	public static final RegistryObject<Block> LARGE_BLUE_CONDUIT_UP = register("large_blue_conduit_up",
			() -> new LargeBlueConduitUp(BlockBehaviour.Properties.copy(Blocks.BONE_BLOCK).sound(SoundType.METAL)),
			object -> () -> new BlockItem(object.get(), new Item.Properties().tab(TrekFiles.TREKFILES_TAB)));

	public static final RegistryObject<Block> LARGE_BLUE_CONDUIT_DOWN = register("large_blue_conduit_down",
			() -> new LargeBlueConduitDown(BlockBehaviour.Properties.copy(Blocks.BONE_BLOCK).sound(SoundType.METAL)),
			object -> () -> new BlockItem(object.get(), new Item.Properties().tab(TrekFiles.TREKFILES_TAB)));

	public static final RegistryObject<Block> LARGE_RED_CONDUIT_UP = register("large_red_conduit_up",
			() -> new LargeRedConduitUp(BlockBehaviour.Properties.copy(Blocks.BONE_BLOCK).sound(SoundType.METAL)),
			object -> () -> new BlockItem(object.get(), new Item.Properties().tab(TrekFiles.TREKFILES_TAB)));

	public static final RegistryObject<Block> LARGE_RED_CONDUIT_DOWN = register("large_red_conduit_down",
			() -> new LargeRedConduitDown(BlockBehaviour.Properties.copy(Blocks.BONE_BLOCK).sound(SoundType.METAL)),
			object -> () -> new BlockItem(object.get(), new Item.Properties().tab(TrekFiles.TREKFILES_TAB)));

	private static <T extends Block> RegistryObject<T> registerBlock(final String name,
			final Supplier<? extends T> block) {
		return BLOCKS.register(name, block);
	}

	private static <T extends Block> RegistryObject<T> register(final String name, final Supplier<? extends T> block,
			Function<RegistryObject<T>, Supplier<? extends Item>> item) {
		RegistryObject<T> obj = registerBlock(name, block);
		ITEMS.register(name, item.apply(obj));
		return obj;
	}
}

https://github.com/oneilljp-keyin/TrekFiles/blob/0ae07709966d916227f7b152b28db24e7037ad7b/src/main/java/tech/johnoneill/trekfiles/block/MediumYellowConduitDown.java

package tech.johnoneill.trekfiles.block;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.FenceBlock;
import net.minecraft.world.level.block.PipeBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public class MediumYellowConduitDown extends FenceBlock {

	private static final VoxelShape SHAPE = makeShape();

	public MediumYellowConduitDown(Properties properties) {
		super(properties);
	}

	@Override
	public @NotNull VoxelShape getShape(@NotNull BlockState state, @NotNull BlockGetter level, @NotNull BlockPos pos, @NotNull CollisionContext ctx) {
		return SHAPE;
	}
	public static VoxelShape makeShape() {
		VoxelShape shape = Shapes.empty();
		shape = Shapes.join(shape, Shapes.box(0.1875, 0, 0.1875, 0.8125, 1, 0.8125), BooleanOp.OR);
		shape = Shapes.join(shape, Shapes.box(0.25, 0, 0.125, 0.75, 1, 0.875), BooleanOp.OR);
		shape = Shapes.join(shape, Shapes.box(0.125, 0, 0.25, 0.875, 1, 0.75), BooleanOp.OR);

		return shape;
	}

}

Any help would be really appreciated, my google searches have not been helpful.

Edited by Jack709
Added code directly
Link to comment
Share on other sites

In general vanilla blocks are not designed to be reused by subclassing. They usually have lots of hardcoding.

 

Look at FenceBlock.connectsTo() used by FenceBlock.getStateForPlacement()

In particular how isSameFence() uses block tags to decide if blocks can connect and the hardwiring of FenceGateBlock.

 

You can also try putting a fence gate next to your block to see what happens. 🙂 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Ok, I originally thought that just making a new fenceBlock would be perfect. I'm going off a tutorial where they did the extending of blocks to make a new one. The original mod just changed the blockstate json of Oak Fence to get it to work. And I thought how I did the Large Conduit would work the same.

I did notice connectsTo() and getStateForPlacement() before, but when I tried to override them, nothing seem to work right.

I'll have to look into block tags, I didn't realize how important they might be.

And placing a gate next to the block makes it do what it's suppose to. Block works fine when a regular block is placed next to it, goes weird when another MediumYellowConduitDown does next to it. And I also noticed that sometimes, the opposite direction is flagged true when I place the block.

So I'm guessing maybe just extend a regular block and do all the state settings in there??

Thanks for all the notes, will most likely be back with some more questions later :)

Edited by Jack709
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.