Skip to content

Commit

Permalink
fix incorrect redstone connection masks (#149)
Browse files Browse the repository at this point in the history
* fix incorrect redstone connection masks

* allow canConnectRedstone to handle bottom face

* dont load tick scheduler client-side

* fix invalid conversion placements for buttons and levers

* fix connection masks for vanilla blocks

* add missing vanilla micro materials

* improve multipart placement context
  • Loading branch information
MrTJP authored Nov 3, 2023
1 parent 50a20b3 commit ee4de53
Show file tree
Hide file tree
Showing 14 changed files with 309 additions and 69 deletions.
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mc_version=1.18.2
forge_version=40.0.19
mod_version=3.1.0
mod_version=3.1.1

ccl_version=4.1.4.+
ccl_version_max=5.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import codechicken.microblock.api.MicroMaterial;
import codechicken.microblock.item.ItemMicroBlock;
import codechicken.microblock.item.SawItem;
import codechicken.microblock.part.MicroblockPartFactory;
import codechicken.microblock.part.corner.CornerMicroFactory;
import codechicken.microblock.part.edge.EdgeMicroFactory;
import codechicken.microblock.part.edge.PostMicroblockFactory;
Expand All @@ -23,6 +24,7 @@
import net.minecraft.world.item.crafting.SimpleRecipeSerializer;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.RedstoneLampBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.IEventBus;
Expand All @@ -47,7 +49,7 @@ public class CBMicroblockModContent {
private static final DeferredRegister<MultipartType<?>> MULTIPART_TYPES = DeferredRegister.create(new ResourceLocation(CBMultipart.MOD_ID, "multipart_types"), CBMicroblock.MOD_ID);
private static final DeferredRegister<RecipeSerializer<?>> RECIPE_SERIALIZERS = DeferredRegister.create(Registry.RECIPE_SERIALIZER_REGISTRY, CBMicroblock.MOD_ID);

public static final SimpleCreativeTab MICRO_TAB = new SimpleCreativeTab("cb_microblock", () -> new ItemStack(Blocks.STONE)) {
public static final SimpleCreativeTab MICRO_TAB = new SimpleCreativeTab("cb_microblock", () -> ItemMicroBlock.create(1, 2, MicroMaterialRegistry.getMaterial(BlockMicroMaterial.makeMaterialKey(Blocks.GRASS_BLOCK.defaultBlockState())))) {
@Override
public boolean hasSearchBar() {
return true;
Expand Down Expand Up @@ -104,6 +106,7 @@ private static void onProcessIMC(InterModProcessEvent event) {
}

private static void onRegisterMicroMaterials(RegistryEvent.Register<MicroMaterial> event) {
// Note: Intentionally kept in same order as Blocks class
IForgeRegistry<MicroMaterial> r = event.getRegistry();
r.register(new BlockMicroMaterial(Blocks.STONE));
r.register(new BlockMicroMaterial(Blocks.GRANITE));
Expand All @@ -127,20 +130,24 @@ private static void onRegisterMicroMaterials(RegistryEvent.Register<MicroMateria
r.register(new BlockMicroMaterial(Blocks.RED_SAND)); //TODO Gravity?
r.register(new BlockMicroMaterial(Blocks.GRAVEL));
r.register(new BlockMicroMaterial(Blocks.GOLD_ORE));
r.register(new BlockMicroMaterial(Blocks.DEEPSLATE_GOLD_ORE));
r.register(new BlockMicroMaterial(Blocks.IRON_ORE));
r.register(new BlockMicroMaterial(Blocks.DEEPSLATE_IRON_ORE));
r.register(new BlockMicroMaterial(Blocks.COAL_ORE));
r.register(new BlockMicroMaterial(Blocks.DEEPSLATE_COAL_ORE));
r.register(new BlockMicroMaterial(Blocks.NETHER_GOLD_ORE));
r.register(new BlockMicroMaterial(Blocks.OAK_LOG));
r.register(new BlockMicroMaterial(Blocks.SPRUCE_LOG));
r.register(new BlockMicroMaterial(Blocks.BIRCH_LOG));
r.register(new BlockMicroMaterial(Blocks.JUNGLE_LOG));
r.register(new BlockMicroMaterial(Blocks.ACACIA_LOG));
r.register(new BlockMicroMaterial(Blocks.DARK_OAK_LOG));
r.register(new BlockMicroMaterial(Blocks.STRIPPED_OAK_LOG));
r.register(new BlockMicroMaterial(Blocks.STRIPPED_SPRUCE_LOG));
r.register(new BlockMicroMaterial(Blocks.STRIPPED_BIRCH_LOG));
r.register(new BlockMicroMaterial(Blocks.STRIPPED_JUNGLE_LOG));
r.register(new BlockMicroMaterial(Blocks.STRIPPED_ACACIA_LOG));
r.register(new BlockMicroMaterial(Blocks.STRIPPED_DARK_OAK_LOG));
r.register(new BlockMicroMaterial(Blocks.STRIPPED_OAK_LOG));
r.register(new BlockMicroMaterial(Blocks.OAK_WOOD));
r.register(new BlockMicroMaterial(Blocks.SPRUCE_WOOD));
r.register(new BlockMicroMaterial(Blocks.BIRCH_WOOD));
Expand All @@ -159,10 +166,13 @@ private static void onRegisterMicroMaterials(RegistryEvent.Register<MicroMateria
r.register(new BlockMicroMaterial(Blocks.JUNGLE_LEAVES));
r.register(new BlockMicroMaterial(Blocks.ACACIA_LEAVES));
r.register(new BlockMicroMaterial(Blocks.DARK_OAK_LEAVES));
r.register(new BlockMicroMaterial(Blocks.AZALEA_LEAVES));
r.register(new BlockMicroMaterial(Blocks.FLOWERING_AZALEA_LEAVES));
r.register(new BlockMicroMaterial(Blocks.SPONGE));
r.register(new BlockMicroMaterial(Blocks.WET_SPONGE));
r.register(new BlockMicroMaterial(Blocks.GLASS));
r.register(new BlockMicroMaterial(Blocks.LAPIS_ORE));
r.register(new BlockMicroMaterial(Blocks.DEEPSLATE_LAPIS_ORE));
r.register(new BlockMicroMaterial(Blocks.LAPIS_BLOCK));
r.register(new BlockMicroMaterial(Blocks.SANDSTONE));
r.register(new BlockMicroMaterial(Blocks.CHISELED_SANDSTONE));
Expand Down Expand Up @@ -191,15 +201,20 @@ private static void onRegisterMicroMaterials(RegistryEvent.Register<MicroMateria
r.register(new BlockMicroMaterial(Blocks.MOSSY_COBBLESTONE));
r.register(new BlockMicroMaterial(Blocks.OBSIDIAN));
r.register(new BlockMicroMaterial(Blocks.DIAMOND_ORE));
r.register(new BlockMicroMaterial(Blocks.DEEPSLATE_DIAMOND_ORE));
r.register(new BlockMicroMaterial(Blocks.DIAMOND_BLOCK));
r.register(new BlockMicroMaterial(Blocks.CRAFTING_TABLE)); //TODO Actually function?
r.register(new BlockMicroMaterial(Blocks.REDSTONE_ORE));
r.register(new BlockMicroMaterial(Blocks.DEEPSLATE_REDSTONE_ORE));
r.register(new BlockMicroMaterial(Blocks.ICE));
r.register(new BlockMicroMaterial(Blocks.SNOW_BLOCK));
r.register(new BlockMicroMaterial(Blocks.CLAY));
r.register(new BlockMicroMaterial(Blocks.PUMPKIN));
r.register(new BlockMicroMaterial(Blocks.NETHERRACK));
r.register(new BlockMicroMaterial(Blocks.SOUL_SAND));
r.register(new BlockMicroMaterial(Blocks.SOUL_SOIL));
r.register(new BlockMicroMaterial(Blocks.BASALT));
r.register(new BlockMicroMaterial(Blocks.POLISHED_BASALT));
r.register(new BlockMicroMaterial(Blocks.GLOWSTONE));
r.register(new BlockMicroMaterial(Blocks.CARVED_PUMPKIN));
r.register(new BlockMicroMaterial(Blocks.JACK_O_LANTERN));
Expand Down Expand Up @@ -230,7 +245,9 @@ private static void onRegisterMicroMaterials(RegistryEvent.Register<MicroMateria
r.register(new BlockMicroMaterial(Blocks.MYCELIUM));
r.register(new BlockMicroMaterial(Blocks.NETHER_BRICKS));
r.register(new BlockMicroMaterial(Blocks.END_STONE));
r.register(new BlockMicroMaterial(Blocks.REDSTONE_LAMP.defaultBlockState().setValue(RedstoneLampBlock.LIT, true)));
r.register(new BlockMicroMaterial(Blocks.EMERALD_ORE));
r.register(new BlockMicroMaterial(Blocks.DEEPSLATE_EMERALD_ORE));
r.register(new BlockMicroMaterial(Blocks.EMERALD_BLOCK));
r.register(new BlockMicroMaterial(Blocks.REDSTONE_BLOCK));
r.register(new BlockMicroMaterial(Blocks.NETHER_QUARTZ_ORE));
Expand Down Expand Up @@ -270,7 +287,9 @@ private static void onRegisterMicroMaterials(RegistryEvent.Register<MicroMateria
r.register(new BlockMicroMaterial(Blocks.SMOOTH_QUARTZ));
r.register(new BlockMicroMaterial(Blocks.SMOOTH_RED_SANDSTONE));
r.register(new BlockMicroMaterial(Blocks.PURPUR_BLOCK));
r.register(new BlockMicroMaterial(Blocks.PURPUR_PILLAR));
r.register(new BlockMicroMaterial(Blocks.END_STONE_BRICKS));
r.register(new BlockMicroMaterial(Blocks.DIRT_PATH));
r.register(new BlockMicroMaterial(Blocks.MAGMA_BLOCK)); //TODO Burn?
r.register(new BlockMicroMaterial(Blocks.NETHER_WART_BLOCK));
r.register(new BlockMicroMaterial(Blocks.RED_NETHER_BRICKS));
Expand Down Expand Up @@ -335,6 +354,62 @@ private static void onRegisterMicroMaterials(RegistryEvent.Register<MicroMateria
r.register(new BlockMicroMaterial(Blocks.FIRE_CORAL_BLOCK)); //TODO Dies out of water
r.register(new BlockMicroMaterial(Blocks.HORN_CORAL_BLOCK)); //TODO Dies out of water
r.register(new BlockMicroMaterial(Blocks.BLUE_ICE)); //TODO speed
r.register(new BlockMicroMaterial(Blocks.WARPED_NYLIUM));
r.register(new BlockMicroMaterial(Blocks.WARPED_WART_BLOCK));
r.register(new BlockMicroMaterial(Blocks.CRIMSON_NYLIUM));
r.register(new BlockMicroMaterial(Blocks.CRIMSON_PLANKS));
r.register(new BlockMicroMaterial(Blocks.WARPED_PLANKS));
r.register(new BlockMicroMaterial(Blocks.HONEY_BLOCK));
r.register(new BlockMicroMaterial(Blocks.HONEYCOMB_BLOCK));
r.register(new BlockMicroMaterial(Blocks.NETHERITE_BLOCK));
r.register(new BlockMicroMaterial(Blocks.ANCIENT_DEBRIS));
r.register(new BlockMicroMaterial(Blocks.CRYING_OBSIDIAN));
r.register(new BlockMicroMaterial(Blocks.LODESTONE));
r.register(new BlockMicroMaterial(Blocks.BLACKSTONE));
r.register(new BlockMicroMaterial(Blocks.POLISHED_BLACKSTONE));
r.register(new BlockMicroMaterial(Blocks.POLISHED_BLACKSTONE_BRICKS));
r.register(new BlockMicroMaterial(Blocks.CRACKED_POLISHED_BLACKSTONE_BRICKS));
r.register(new BlockMicroMaterial(Blocks.CHISELED_POLISHED_BLACKSTONE));
r.register(new BlockMicroMaterial(Blocks.GILDED_BLACKSTONE));
r.register(new BlockMicroMaterial(Blocks.CHISELED_NETHER_BRICKS));
r.register(new BlockMicroMaterial(Blocks.CRACKED_NETHER_BRICKS));
r.register(new BlockMicroMaterial(Blocks.QUARTZ_BRICKS));
r.register(new BlockMicroMaterial(Blocks.AMETHYST_BLOCK));
r.register(new BlockMicroMaterial(Blocks.TUFF));
r.register(new BlockMicroMaterial(Blocks.CALCITE));
r.register(new BlockMicroMaterial(Blocks.TINTED_GLASS));
r.register(new BlockMicroMaterial(Blocks.OXIDIZED_COPPER));
r.register(new BlockMicroMaterial(Blocks.WEATHERED_COPPER));
r.register(new BlockMicroMaterial(Blocks.EXPOSED_COPPER));
r.register(new BlockMicroMaterial(Blocks.COPPER_BLOCK)); //TODO Oxidization (normal -> exposed -> weathered -> oxidized)
r.register(new BlockMicroMaterial(Blocks.COPPER_ORE));
r.register(new BlockMicroMaterial(Blocks.DEEPSLATE_COPPER_ORE));
r.register(new BlockMicroMaterial(Blocks.OXIDIZED_CUT_COPPER));
r.register(new BlockMicroMaterial(Blocks.WEATHERED_CUT_COPPER));
r.register(new BlockMicroMaterial(Blocks.EXPOSED_CUT_COPPER));
r.register(new BlockMicroMaterial(Blocks.CUT_COPPER)); //TODO Oxidization (normal -> exposed -> weathered -> oxidized)
r.register(new BlockMicroMaterial(Blocks.WAXED_COPPER_BLOCK));
r.register(new BlockMicroMaterial(Blocks.WAXED_WEATHERED_COPPER));
r.register(new BlockMicroMaterial(Blocks.WAXED_EXPOSED_COPPER));
r.register(new BlockMicroMaterial(Blocks.WAXED_OXIDIZED_COPPER));
r.register(new BlockMicroMaterial(Blocks.WAXED_OXIDIZED_CUT_COPPER));
r.register(new BlockMicroMaterial(Blocks.WAXED_WEATHERED_CUT_COPPER));
r.register(new BlockMicroMaterial(Blocks.WAXED_EXPOSED_CUT_COPPER));
r.register(new BlockMicroMaterial(Blocks.WAXED_CUT_COPPER));
r.register(new BlockMicroMaterial(Blocks.DRIPSTONE_BLOCK));
r.register(new BlockMicroMaterial(Blocks.ROOTED_DIRT));
r.register(new BlockMicroMaterial(Blocks.DEEPSLATE));
r.register(new BlockMicroMaterial(Blocks.COBBLED_DEEPSLATE));
r.register(new BlockMicroMaterial(Blocks.POLISHED_DEEPSLATE));
r.register(new BlockMicroMaterial(Blocks.DEEPSLATE_TILES));
r.register(new BlockMicroMaterial(Blocks.DEEPSLATE_BRICKS));
r.register(new BlockMicroMaterial(Blocks.CHISELED_DEEPSLATE));
r.register(new BlockMicroMaterial(Blocks.CRACKED_DEEPSLATE_BRICKS));
r.register(new BlockMicroMaterial(Blocks.CRACKED_DEEPSLATE_TILES));
r.register(new BlockMicroMaterial(Blocks.SMOOTH_BASALT));
r.register(new BlockMicroMaterial(Blocks.RAW_IRON_BLOCK));
r.register(new BlockMicroMaterial(Blocks.RAW_COPPER_BLOCK));
r.register(new BlockMicroMaterial(Blocks.RAW_GOLD_BLOCK));
}

private static void processIMC(InterModProcessEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import codechicken.microblock.api.MicroMaterial;
import codechicken.multipart.api.part.MultiPart;
import codechicken.multipart.block.TileMultipart;
import codechicken.multipart.util.ControlKeyModifier;
import codechicken.multipart.util.MultipartHelper;
import codechicken.multipart.util.OffsetUseOnContext;
import codechicken.multipart.util.PartRayTraceResult;
import codechicken.multipart.util.*;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
Expand Down Expand Up @@ -152,7 +149,7 @@ public ExecutablePlacement externalPlacement(int slot) {
@Nullable
public ExecutablePlacement externalPlacement(MicroblockPart part) {
BlockPos pos = this.pos.relative(Direction.from3DDataValue(side));
if (TileMultipart.canPlacePart(new OffsetUseOnContext(new UseOnContext(player, hand, hit)), part)) {
if (TileMultipart.canPlacePart(new MultipartPlaceContext(player, hand, hit).applyOffset(), part)) {
return new ExecutablePlacement.AdditionPlacement(pos, part);
}
return null;
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/codechicken/multipart/api/ItemMultipart.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package codechicken.multipart.api;

import codechicken.lib.vec.Rotation;
import codechicken.lib.vec.Vector3;
import codechicken.multipart.api.part.MultiPart;
import codechicken.multipart.block.TileMultipart;
import codechicken.multipart.util.OffsetUseOnContext;
import codechicken.multipart.util.MultipartPlaceContext;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SoundType;
import org.apache.commons.lang3.NotImplementedException;
import org.jetbrains.annotations.Nullable;

/**
Expand All @@ -24,22 +23,28 @@ public ItemMultipart(Properties properties) {
}

@Nullable
public abstract MultiPart newPart(UseOnContext context);
@Deprecated(since = "1.18.2", forRemoval = true) // Override newPart(MultipartPlaceContext) instead
public MultiPart newPart(UseOnContext context) {
throw new NotImplementedException();
}

@Nullable
public MultiPart newPart(MultipartPlaceContext context) {
return newPart((UseOnContext) context);
}

@Override
public InteractionResult useOn(UseOnContext context) {

Vector3 vHit = new Vector3(context.getClickLocation()).subtract(context.getClickedPos());
double hitDepth = getHitDepth(vHit, context.getClickedFace().ordinal());
MultipartPlaceContext ctx = new MultipartPlaceContext(context);

if (hitDepth < 1 && place(context)) {
if (ctx.getHitDepth() < 1 && place(ctx)) {
return InteractionResult.SUCCESS;
}

return place(new OffsetUseOnContext(context)) ? InteractionResult.SUCCESS : InteractionResult.FAIL;
return place(ctx.applyOffset()) ? InteractionResult.SUCCESS : InteractionResult.FAIL;
}

private boolean place(UseOnContext context) {
private boolean place(MultipartPlaceContext context) {
Level world = context.getLevel();
BlockPos pos = context.getClickedPos();

Expand All @@ -59,9 +64,4 @@ private boolean place(UseOnContext context) {
}
return true;
}

public static double getHitDepth(Vector3 vHit, int side) {
return vHit.scalarProject(Rotation.axes[side]) + (side % 2 ^ 1);
}

}
8 changes: 7 additions & 1 deletion src/main/java/codechicken/multipart/api/PartConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import codechicken.multipart.CBMultipart;
import codechicken.multipart.api.part.MultiPart;
import codechicken.multipart.util.MultipartPlaceContext;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -46,10 +47,15 @@ public ConversionResult<Collection<MultiPart>> convert(LevelAccessor world, Bloc
/**
* Convert an {@link ItemStack} about to be placed into a {@link MultiPart} instance.
*
* @param context The {@link UseOnContext} for the placement.
* @param context The {@link MultipartPlaceContext} for the placement.
* @return A {@link ConversionResult}, providing the {@link MultiPart} instance if conversion
* was successful.
*/
public ConversionResult<MultiPart> convert(MultipartPlaceContext context) {
return convert((UseOnContext) context);
}

@Deprecated(since = "1.18.2", forRemoval = true) // Use convert(MultipartPlaceContext)
public ConversionResult<MultiPart> convert(UseOnContext context) {
return emptyResult();
}
Expand Down
Loading

0 comments on commit ee4de53

Please sign in to comment.