Update EndTrapdoorBlock.java
This commit is contained in:
parent
2048ebae22
commit
9f98e6f3f8
1 changed files with 49 additions and 4 deletions
|
@ -1,18 +1,21 @@
|
||||||
package ru.betterend.blocks.basis;
|
package ru.betterend.blocks.basis;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||||
|
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||||
|
import net.minecraft.client.resources.model.BlockModelRotation;
|
||||||
|
import net.minecraft.client.resources.model.UnbakedModel;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
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.Block;
|
||||||
import net.minecraft.world.level.block.TrapDoorBlock;
|
import net.minecraft.world.level.block.TrapDoorBlock;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.block.state.properties.Half;
|
||||||
import net.minecraft.world.level.storage.loot.LootContext;
|
import net.minecraft.world.level.storage.loot.LootContext;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import ru.betterend.client.models.ModelsHelper;
|
||||||
import ru.betterend.client.render.ERenderLayer;
|
import ru.betterend.client.render.ERenderLayer;
|
||||||
import ru.betterend.interfaces.IRenderTypeable;
|
import ru.betterend.interfaces.IRenderTypeable;
|
||||||
import ru.betterend.client.models.BlockModelProvider;
|
import ru.betterend.client.models.BlockModelProvider;
|
||||||
|
@ -46,4 +49,46 @@ public class EndTrapdoorBlock extends TrapDoorBlock implements IRenderTypeable,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockModel getModel(ResourceLocation resourceLocation) {
|
||||||
|
return getBlockModel(resourceLocation, defaultBlockState());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||||
|
String name = resourceLocation.getPath();
|
||||||
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_TRAPDOOR, new HashMap<String, String>() {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
{
|
||||||
|
put("%block%", name);
|
||||||
|
put("%texture%", name.replace("trapdoor", "door_side"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return ModelsHelper.fromPattern(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||||
|
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(), "block/" + resourceLocation.getPath());
|
||||||
|
boolean isTop = blockState.getValue(HALF) == Half.TOP;
|
||||||
|
boolean isOpen = blockState.getValue(OPEN);
|
||||||
|
int y = 0;
|
||||||
|
int x = (isTop && isOpen) ? 270 : isTop ? 180 : isOpen ? 90 : 0;
|
||||||
|
switch (blockState.getValue(FACING)) {
|
||||||
|
case EAST:
|
||||||
|
y = (isTop && isOpen) ? 270 : 90;
|
||||||
|
break;
|
||||||
|
case NORTH:
|
||||||
|
if (isTop && isOpen) y = 180;
|
||||||
|
break;
|
||||||
|
case SOUTH:
|
||||||
|
y = (isTop && isOpen) ? 0 : 180;
|
||||||
|
break;
|
||||||
|
case WEST:
|
||||||
|
y = (isTop && isOpen) ? 90 : 270;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
BlockModelRotation rotation = BlockModelRotation.by(x, y);
|
||||||
|
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue