The full spectrum

- Water wheel material lookup supports any reasonably implemented wood type
- Water wheel items use spruce
- Cleanup mtls
This commit is contained in:
simibubi 2023-02-25 03:59:24 +01:00
parent 9271edf298
commit 55c314f6dc
6 changed files with 61 additions and 88 deletions

View file

@ -26,6 +26,7 @@ import net.minecraft.util.Mth;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BubbleColumnBlock; import net.minecraft.world.level.block.BubbleColumnBlock;
import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.BlockEntityType;
@ -89,8 +90,11 @@ public class WaterWheelBlockEntity extends GeneratingKineticBlockEntity {
return InteractionResult.PASS; return InteractionResult.PASS;
if (!material.is(BlockTags.PLANKS)) if (!material.is(BlockTags.PLANKS))
return InteractionResult.PASS; return InteractionResult.PASS;
if (level.isClientSide())
return InteractionResult.SUCCESS;
this.material = material; this.material = material;
notifyUpdate(); notifyUpdate();
level.levelEvent(2001, worldPosition, Block.getId(material));
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} }

View file

@ -1,7 +1,9 @@
package com.simibubi.create.content.contraptions.components.waterwheel; package com.simibubi.create.content.contraptions.components.waterwheel;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.Optional;
import java.util.Random;
import com.jozufozu.flywheel.core.PartialModel; import com.jozufozu.flywheel.core.PartialModel;
import com.jozufozu.flywheel.core.StitchedSprite; import com.jozufozu.flywheel.core.StitchedSprite;
@ -18,16 +20,18 @@ import com.simibubi.create.foundation.utility.RegisteredObjects;
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap; import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider.Context; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider.Context;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.BakedModel; import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.Direction.AxisDirection; import net.minecraft.core.Direction.AxisDirection;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.registries.ForgeRegistries;
public class WaterWheelRenderer<T extends WaterWheelBlockEntity> extends KineticBlockEntityRenderer<T> { public class WaterWheelRenderer<T extends WaterWheelBlockEntity> extends KineticBlockEntityRenderer<T> {
public static final Compartment<WaterWheelModelKey> WATER_WHEEL = new Compartment<>(); public static final Compartment<WaterWheelModelKey> WATER_WHEEL = new Compartment<>();
@ -91,25 +95,51 @@ public class WaterWheelRenderer<T extends WaterWheelBlockEntity> extends Kinetic
boolean extension = key.state().getOptionalValue(LargeWaterWheelBlock.EXTENSION).orElse(false); boolean extension = key.state().getOptionalValue(LargeWaterWheelBlock.EXTENSION).orElse(false);
BakedModel template = getTemplateModel(key.large(), extension).get(); BakedModel template = getTemplateModel(key.large(), extension).get();
// TODO waterwheels: improve sprite selection BlockState planksBlockState = key.material();
BlockState material = key.material(); Block planksBlock = planksBlockState.getBlock();
Block block = material.getBlock(); ResourceLocation id = RegisteredObjects.getKeyOrThrow(planksBlock);
ResourceLocation id = RegisteredObjects.getKeyOrThrow(block);
String path = id.getPath(); String path = id.getPath();
if (path.endsWith("_planks")) { if (path.endsWith("_planks")) {
String namespace = id.getNamespace(); String namespace = id.getNamespace();
String wood = path.substring(0, path.length() - 7); String wood = path.substring(0, path.length() - 7);
Function<ResourceLocation, TextureAtlasSprite> spriteFunc = Minecraft.getInstance().getTextureAtlas(TextureAtlas.LOCATION_BLOCKS); BlockState logBlockState = getLogBlockState(namespace, wood);
Map<TextureAtlasSprite, TextureAtlasSprite> map = new Reference2ReferenceOpenHashMap<>(); Map<TextureAtlasSprite, TextureAtlasSprite> map = new Reference2ReferenceOpenHashMap<>();
map.put(OAK_PLANKS_TEMPLATE.get(), spriteFunc.apply(new ResourceLocation(namespace, "block/" + wood + "_planks"))); map.put(OAK_PLANKS_TEMPLATE.get(), getSpriteOnSide(planksBlockState, Direction.UP));
map.put(OAK_LOG_TEMPLATE.get(), spriteFunc.apply(new ResourceLocation(namespace, "block/" + wood + "_log"))); map.put(OAK_LOG_TEMPLATE.get(), getSpriteOnSide(logBlockState, Direction.NORTH));
map.put(OAK_LOG_TOP_TEMPLATE.get(), spriteFunc.apply(new ResourceLocation(namespace, "block/" + wood + "_log_top"))); map.put(OAK_LOG_TOP_TEMPLATE.get(), getSpriteOnSide(logBlockState, Direction.UP));
return BakedModelHelper.generateModel(template, map::get); return BakedModelHelper.generateModel(template, map::get);
} }
return BakedModelHelper.generateModel(template, sprite -> null); return BakedModelHelper.generateModel(template, sprite -> null);
} }
private static BlockState getLogBlockState(String namespace, String wood) {
for (String suffix : new String[] { "_log", "_stem" }) {
Optional<BlockState> state =
ForgeRegistries.BLOCKS.getHolder(new ResourceLocation(namespace, wood + suffix))
.map(Holder::value)
.map(Block::defaultBlockState);
if (state.isPresent())
return state.get();
}
return Blocks.OAK_LOG.defaultBlockState();
}
private static TextureAtlasSprite getSpriteOnSide(BlockState blockstate, Direction side) {
BakedModel blockModel = Minecraft.getInstance()
.getBlockRenderer()
.getBlockModel(blockstate);
if (blockModel == null)
return null;
@SuppressWarnings("deprecation")
List<BakedQuad> quads = blockModel.getQuads(blockstate, side, new Random());
if (quads.isEmpty())
return null;
return quads.get(0)
.getSprite();
}
} }

View file

@ -17,6 +17,7 @@ import net.minecraft.client.particle.ParticleEngine;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
@ -85,6 +86,16 @@ public class WaterWheelStructuralBlock extends DirectionalBlock implements IWren
return IWrenchable.super.onSneakWrenched(state, context); return IWrenchable.super.onSneakWrenched(state, context);
} }
@Override
public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand,
BlockHitResult pHit) {
if (!stillValid(pLevel, pPos, pState, false))
return InteractionResult.FAIL;
if (!(pLevel.getBlockEntity(getMaster(pLevel, pPos, pState))instanceof WaterWheelBlockEntity wwt))
return InteractionResult.FAIL;
return wwt.applyMaterialIfValid(pPlayer.getItemInHand(pHand));
}
@Override @Override
public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pIsMoving) { public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pIsMoving) {
if (stillValid(pLevel, pPos, pState, false)) if (stillValid(pLevel, pPos, pState, false))

View file

@ -2,51 +2,16 @@
# www.blender.org # www.blender.org
newmtl crushing_wheel_insert newmtl crushing_wheel_insert
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd #insert map_Kd #insert
newmtl crushing_wheel_plates newmtl crushing_wheel_plates
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd #plates map_Kd #plates
newmtl m_axis newmtl m_axis
Ns 0.000000
Ka 1.000000 1.000000 1.000000
Ks 0.000000 0.000000 0.000000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 1
map_Kd #axis map_Kd #axis
newmtl m_axis_top newmtl m_axis_top
Ns 0.000000
Ka 1.000000 1.000000 1.000000
Ks 0.000000 0.000000 0.000000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 1
map_Kd #axis_top map_Kd #axis_top
newmtl m_spruce_log_top.001 newmtl m_spruce_log_top.001
Ns 0.000000
Ka 1.000000 1.000000 1.000000
Ks 0.000000 0.000000 0.000000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 1
map_Kd #spruce_log_top map_Kd #spruce_log_top

View file

@ -3,6 +3,11 @@
"loader": "forge:obj", "loader": "forge:obj",
"flip-v": true, "flip-v": true,
"model": "create:models/block/large_water_wheel/waterwheel_large.obj", "model": "create:models/block/large_water_wheel/waterwheel_large.obj",
"textures": {
"log": "block/spruce_log",
"planks": "block/spruce_planks",
"log_top": "block/spruce_log_top"
},
"display": { "display": {
"gui": { "gui": {
"rotation": [ 30, 225, 0 ], "rotation": [ 30, 225, 0 ],

View file

@ -2,61 +2,19 @@
# www.blender.org # www.blender.org
newmtl axis newmtl axis
Ns 0.000000
Ka 1.000000 1.000000 1.000000
Ks 0.000000 0.000000 0.000000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 1
map_Kd #axis map_Kd #axis
newmtl axis_top newmtl axis_top
Ns 0.000000
Ka 1.000000 1.000000 1.000000
Ks 0.000000 0.000000 0.000000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 1
map_Kd #axis_top map_Kd #axis_top
newmtl waterwheel_log newmtl waterwheel_log
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd #log map_Kd #log
newmtl waterwheel_metal newmtl waterwheel_metal
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd #metal map_Kd #metal
newmtl waterwheel_plank newmtl waterwheel_plank
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd #planks map_Kd #planks
newmtl waterwheel_stripped_log newmtl waterwheel_stripped_log
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd #log_top map_Kd #log_top