Skip to content

Commit

Permalink
Placeholder previews & start of placement handlers
Browse files Browse the repository at this point in the history
Part of #38.

 - Disabled `PlacementHandler` until render behavior complete
 - Fixed tile entity rendering
 - Todo: stone & soil placeholder rendering
  • Loading branch information
natrow committed Jul 19, 2023
1 parent 531c64d commit 02c16ed
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
@Mixin(value = BlueprintRenderer.class, remap = false)
public abstract class BlueprintRendererMixin implements AutoCloseable
{
// Override BlockState of placeholder blocks
@ModifyVariable(method = "init", name = "state", at = @At("STORE"))
BlockState initInjector(BlockState value)
private BlockState initInjector(BlockState value)
{
// Safe to access settings instances within this function
if (Settings.instance.renderLightPlaceholders() && TFCMConstants.PLACEHOLDER_TO_WOOD.get().containsKey(value.getBlock()))
{
final String woodType = ((ISettingsExtension) (Object) Settings.instance).getWoodType().toLowerCase(Locale.ROOT);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.natrow.tfc_minecolonies.mixin;

import java.util.Locale;
import com.ldtteam.structurize.blueprints.v1.BlueprintUtils;
import com.ldtteam.structurize.client.BlueprintBlockAccess;
import com.ldtteam.structurize.helpers.Settings;
import com.ldtteam.structurize.util.BlockInfo;
import com.natrow.tfc_minecolonies.TFCMConstants;
import com.natrow.tfc_minecolonies.structurize.ISettingsExtension;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(value = BlueprintUtils.class, remap = false)
public abstract class BlueprintUtilsMixin
{
@Inject(method = "constructTileEntity", at = @At(value = "RETURN", ordinal = 1), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
private static void constructTileEntityInjector(BlockInfo info, BlueprintBlockAccess blockAccess, CallbackInfoReturnable<BlockEntity> cir, String entityId, CompoundTag compound, BlockEntity entity)
{
final BlockState value = entity.getBlockState();
if (Settings.instance.renderLightPlaceholders() && TFCMConstants.PLACEHOLDER_TO_WOOD.get().containsKey(value.getBlock()))
{
final String woodType = ((ISettingsExtension) (Object) Settings.instance).getWoodType().toLowerCase(Locale.ROOT);
final Block targetBlock = TFCMConstants.PLACEHOLDER_TO_WOOD.get().get(value.getBlock()).get(woodType);
entity.setBlockState(targetBlock.withPropertiesOf(value));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.List;
import com.ldtteam.structurize.placement.handlers.placement.IPlacementHandler;
import com.ldtteam.structurize.placement.handlers.placement.PlacementHandlers;
import com.ldtteam.structurize.util.PlacementSettings;
import com.natrow.tfc_minecolonies.TFCMConstants;
import com.natrow.tfc_minecolonies.item.TFCMItems;
import net.minecraft.core.BlockPos;
Expand All @@ -16,7 +15,6 @@
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BedBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BedPart;
import org.jetbrains.annotations.Nullable;
Expand All @@ -34,7 +32,6 @@
import net.dries007.tfc.common.blocks.soil.FarmlandBlock;
import net.dries007.tfc.common.blocks.soil.ISoilBlock;
import net.dries007.tfc.common.blocks.soil.PathBlock;
import net.dries007.tfc.common.blocks.wood.Wood;
import net.dries007.tfc.common.items.HideItemType;
import net.dries007.tfc.common.items.TFCItems;
import net.dries007.tfc.util.Helpers;
Expand All @@ -57,7 +54,7 @@ public static void registerHandlers()
PlacementHandlers.add(new TFCFirepitPlacementHandler());
PlacementHandlers.add(new TFCForgeHandler());
PlacementHandlers.add(new TFCTileEntityPlacementHandler());
PlacementHandlers.add(new TFCPlaceholderWoodHandler());
// PlacementHandlers.add(new TFCPlaceholderWoodHandler());
}

/**
Expand Down Expand Up @@ -346,66 +343,68 @@ public List<ItemStack> getRequiredItems(Level level, BlockPos blockPos, BlockSta
}
}

public static class TFCPlaceholderWoodHandler implements IPlacementHandler
{
@Override
public boolean canHandle(Level level, BlockPos blockPos, BlockState blockState)
{
return TFCMConstants.PLACEHOLDER_TO_WOOD.get().containsKey(blockState.getBlock());
}

@Override
public ActionProcessingResult handle(Level world, BlockPos pos, BlockState blockState, @Nullable CompoundTag tileEntityData, boolean complete, BlockPos centerPos, PlacementSettings settings)
{
if (complete)
{
world.setBlock(pos, blockState, UPDATE_FLAG);
return ActionProcessingResult.PASS;
}

final String woodType = Wood.ASH.getSerializedName(); // todo
final Block targetBlock = TFCMConstants.PLACEHOLDER_TO_WOOD.get().get(blockState.getBlock()).get(woodType);

final BlockState targetState = targetBlock.withPropertiesOf(blockState);

for (final IPlacementHandler placementHandler : PlacementHandlers.handlers)
{
if (placementHandler.canHandle(world, pos, targetState))
{
return placementHandler.handle(world, pos, targetState, tileEntityData, false, centerPos, settings);
}
}

throw new RuntimeException("Couldn't find a valid placement handler for placeholder block");
}

@Override
public List<ItemStack> getRequiredItems(Level world, BlockPos pos, BlockState blockState, @Nullable CompoundTag tileEntityData, boolean complete)
{

if (complete)
{
List<ItemStack> itemList = new ArrayList<>();
itemList.add(new ItemStack(blockState.getBlock()));
return itemList;
}
else
{
final String woodType = Wood.ASH.getSerializedName(); // todo
final Block targetBlock = TFCMConstants.PLACEHOLDER_TO_WOOD.get().get(blockState.getBlock()).get(woodType);

final BlockState targetState = targetBlock.withPropertiesOf(blockState);

for (final IPlacementHandler placementHandler : PlacementHandlers.handlers)
{
if (placementHandler.canHandle(world, pos, targetState))
{
return placementHandler.getRequiredItems(world, pos, targetBlock.withPropertiesOf(blockState), tileEntityData, false);
}
}
}

throw new RuntimeException("Couldn't find a valid placement handler for placeholder block");
}
}
// TODO: Placement Handler

// public static class TFCPlaceholderWoodHandler implements IPlacementHandler
// {
// @Override
// public boolean canHandle(Level level, BlockPos blockPos, BlockState blockState)
// {
// return TFCMConstants.PLACEHOLDER_TO_WOOD.get().containsKey(blockState.getBlock());
// }
//
// @Override
// public ActionProcessingResult handle(Level world, BlockPos pos, BlockState blockState, @Nullable CompoundTag tileEntityData, boolean complete, BlockPos centerPos, PlacementSettings settings)
// {
// if (complete)
// {
// world.setBlock(pos, blockState, UPDATE_FLAG);
// return ActionProcessingResult.PASS;
// }
//
// final String woodType = Wood.ASH.getSerializedName(); // todo
// final Block targetBlock = TFCMConstants.PLACEHOLDER_TO_WOOD.get().get(blockState.getBlock()).get(woodType);
//
// final BlockState targetState = targetBlock.withPropertiesOf(blockState);
//
// for (final IPlacementHandler placementHandler : PlacementHandlers.handlers)
// {
// if (placementHandler.canHandle(world, pos, targetState))
// {
// return placementHandler.handle(world, pos, targetState, tileEntityData, false, centerPos, settings);
// }
// }
//
// throw new RuntimeException("Couldn't find a valid placement handler for placeholder block");
// }
//
// @Override
// public List<ItemStack> getRequiredItems(Level world, BlockPos pos, BlockState blockState, @Nullable CompoundTag tileEntityData, boolean complete)
// {
//
// if (complete)
// {
// List<ItemStack> itemList = new ArrayList<>();
// itemList.add(new ItemStack(blockState.getBlock()));
// return itemList;
// }
// else
// {
// final String woodType = Wood.ASH.getSerializedName(); // todo
// final Block targetBlock = TFCMConstants.PLACEHOLDER_TO_WOOD.get().get(blockState.getBlock()).get(woodType);
//
// final BlockState targetState = targetBlock.withPropertiesOf(blockState);
//
// for (final IPlacementHandler placementHandler : PlacementHandlers.handlers)
// {
// if (placementHandler.canHandle(world, pos, targetState))
// {
// return placementHandler.getRequiredItems(world, pos, targetBlock.withPropertiesOf(blockState), tileEntityData, false);
// }
// }
// }
//
// throw new RuntimeException("Couldn't find a valid placement handler for placeholder block");
// }
// }
}
6 changes: 3 additions & 3 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ side = "BOTH"
[[dependencies.tfc_minecolonies]]
modId = "tfc"
mandatory = true
versionRange = "[2.2.6,)"
versionRange = "[2.2.6]"
ordering = "AFTER"
side = "BOTH"
[[dependencies.tfc_minecolonies]]
modId = "minecolonies"
mandatory = true
versionRange = "[1.18.2-1.0.1215-ALPHA,)"
versionRange = "[1.18.2-1.0.1215-ALPHA]"
ordering = "AFTER"
side = "BOTH"
[[dependencies.tfc_minecolonies]]
modId = "structurize"
mandatory = true
versionRange = "[1.18.2-1.0.424-ALPHA,)"
versionRange = "[1.18.2-1.0.424-ALPHA]"
ordering = "AFTER"
side = "BOTH"
[[dependencies.tfc_minecolonies]]
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mixins.tfc_minecolonies.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"required": true,
"package": "com.natrow.tfc_minecolonies.mixin",
"minVersion": "0.8",
"mixins": ["AbstractBlockHutMixin", "BlockEntityTypeAccessor", "ColonyPermissionEventHandlerMixin", "ItemStackUtilsMixin", "NetworkChannelMixin", "SettingsMixin", "TFCChestBlockEntityRendererMixin", "TileEntityColonyBuildingMixin", "ToolMixin", "ToolTypeMixin", "TreeMixin", "WorkerUtilMixin", "AI.AbstractEntityAIInteractMixin", "AI.EntityAIWorkFarmerMixin", "AI.EntityAIWorkLumberjackMixin"],
"mixins": ["AbstractBlockHutMixin", "BlockEntityTypeAccessor", "BlueprintUtilsMixin", "ColonyPermissionEventHandlerMixin", "ItemStackUtilsMixin", "NetworkChannelMixin", "SettingsMixin", "TFCChestBlockEntityRendererMixin", "TileEntityColonyBuildingMixin", "ToolMixin", "ToolTypeMixin", "TreeMixin", "WorkerUtilMixin", "AI.AbstractEntityAIInteractMixin", "AI.EntityAIWorkFarmerMixin", "AI.EntityAIWorkLumberjackMixin"],
"refmap": "mixins.tfc_minecolonies.refmap.json",
"compatibilityLevel": "JAVA_17",
"client": ["BlueprintRendererMixin", "WindowBuildToolMixin", "WindowMinecoloniesBuildToolMixin"]
Expand Down

0 comments on commit 02c16ed

Please sign in to comment.