mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-14 13:23:52 +01:00
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:
parent
9271edf298
commit
55c314f6dc
6 changed files with 61 additions and 88 deletions
|
@ -26,6 +26,7 @@ import net.minecraft.util.Mth;
|
|||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
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.BubbleColumnBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
|
@ -89,8 +90,11 @@ public class WaterWheelBlockEntity extends GeneratingKineticBlockEntity {
|
|||
return InteractionResult.PASS;
|
||||
if (!material.is(BlockTags.PLANKS))
|
||||
return InteractionResult.PASS;
|
||||
if (level.isClientSide())
|
||||
return InteractionResult.SUCCESS;
|
||||
this.material = material;
|
||||
notifyUpdate();
|
||||
level.levelEvent(2001, worldPosition, Block.getId(material));
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package com.simibubi.create.content.contraptions.components.waterwheel;
|
||||
|
||||
import java.util.List;
|
||||
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.StitchedSprite;
|
||||
|
@ -18,16 +20,18 @@ import com.simibubi.create.foundation.utility.RegisteredObjects;
|
|||
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
|
||||
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.texture.TextureAtlas;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Direction.AxisDirection;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
public class WaterWheelRenderer<T extends WaterWheelBlockEntity> extends KineticBlockEntityRenderer<T> {
|
||||
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);
|
||||
BakedModel template = getTemplateModel(key.large(), extension).get();
|
||||
|
||||
// TODO waterwheels: improve sprite selection
|
||||
BlockState material = key.material();
|
||||
Block block = material.getBlock();
|
||||
ResourceLocation id = RegisteredObjects.getKeyOrThrow(block);
|
||||
BlockState planksBlockState = key.material();
|
||||
Block planksBlock = planksBlockState.getBlock();
|
||||
ResourceLocation id = RegisteredObjects.getKeyOrThrow(planksBlock);
|
||||
String path = id.getPath();
|
||||
|
||||
if (path.endsWith("_planks")) {
|
||||
String namespace = id.getNamespace();
|
||||
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.put(OAK_PLANKS_TEMPLATE.get(), spriteFunc.apply(new ResourceLocation(namespace, "block/" + wood + "_planks")));
|
||||
map.put(OAK_LOG_TEMPLATE.get(), spriteFunc.apply(new ResourceLocation(namespace, "block/" + wood + "_log")));
|
||||
map.put(OAK_LOG_TOP_TEMPLATE.get(), spriteFunc.apply(new ResourceLocation(namespace, "block/" + wood + "_log_top")));
|
||||
map.put(OAK_PLANKS_TEMPLATE.get(), getSpriteOnSide(planksBlockState, Direction.UP));
|
||||
map.put(OAK_LOG_TEMPLATE.get(), getSpriteOnSide(logBlockState, Direction.NORTH));
|
||||
map.put(OAK_LOG_TOP_TEMPLATE.get(), getSpriteOnSide(logBlockState, Direction.UP));
|
||||
|
||||
return BakedModelHelper.generateModel(template, map::get);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import net.minecraft.client.particle.ParticleEngine;
|
|||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
@ -85,6 +86,16 @@ public class WaterWheelStructuralBlock extends DirectionalBlock implements IWren
|
|||
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
|
||||
public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pIsMoving) {
|
||||
if (stillValid(pLevel, pPos, pState, false))
|
||||
|
|
|
@ -2,51 +2,16 @@
|
|||
# www.blender.org
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
"loader": "forge:obj",
|
||||
"flip-v": true,
|
||||
"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": {
|
||||
"gui": {
|
||||
"rotation": [ 30, 225, 0 ],
|
||||
|
|
|
@ -2,61 +2,19 @@
|
|||
# www.blender.org
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue