Skip to content

Commit

Permalink
Added trapdoors
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicSquid committed May 19, 2019
1 parent 00dbcec commit ba7ae6a
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/main/java/epicsquid/blockcraftery/RegistryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import epicsquid.blockcraftery.block.BlockEditableSlab;
import epicsquid.blockcraftery.block.BlockEditableSlant;
import epicsquid.blockcraftery.block.BlockEditableStairs;
import epicsquid.blockcraftery.block.BlockEditableTrapDoor;
import epicsquid.blockcraftery.block.BlockEditableWall;
import epicsquid.blockcraftery.block.EditableBlockColors;
import epicsquid.blockcraftery.tile.TileEditableBlock;
import epicsquid.mysticallib.LibRegistry;
import epicsquid.mysticallib.block.BlockSlabBase;
import epicsquid.mysticallib.block.BlockTrapDoorBase;
import epicsquid.mysticallib.event.RegisterColorHandlersEvent;
import epicsquid.mysticallib.event.RegisterContentEvent;
import epicsquid.mysticallib.event.RegisterModRecipesEvent;
Expand All @@ -19,6 +21,8 @@
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
Expand All @@ -27,7 +31,7 @@
public class RegistryManager {
private static int entityId = 0;

public static Block editable_block, editable_stairs, editable_slab, editable_double_slab, editable_slant, editable_outer_corner, editable_inner_corner, editable_wall, editable_fence, editable_block_reinforced, editable_stairs_reinforced, editable_slab_reinforced, editable_double_slab_reinforced, editable_slant_reinforced, editable_outer_corner_reinforced, editable_inner_corner_reinforced, editable_wall_reinforced, editable_fence_reinforced;
public static Block editable_block, editable_stairs, editable_slab, editable_double_slab, editable_slant, editable_outer_corner, editable_inner_corner, editable_wall, editable_fence, editable_block_reinforced, editable_stairs_reinforced, editable_slab_reinforced, editable_double_slab_reinforced, editable_slant_reinforced, editable_outer_corner_reinforced, editable_inner_corner_reinforced, editable_wall_reinforced, editable_fence_reinforced, editable_trap_door, editable_trap_door_reinforced;

@SubscribeEvent
public void registerContent(RegisterContentEvent event) {
Expand Down Expand Up @@ -60,6 +64,9 @@ public void registerContent(RegisterContentEvent event) {
editable_inner_corner_reinforced = event.addBlock(new BlockEditableCorner(editable_block_reinforced.getDefaultState(), SoundType.WOOD, 1.0f, "editable_inner_corner_reinforced", true, TileEditableBlock.class).setResistance(60000f).setFlammable(false).setCreativeTab(Blockcraftery.tab));
editable_wall_reinforced = event.addBlock(new BlockEditableWall(editable_block_reinforced, SoundType.WOOD, 1.0f, "editable_wall_reinforced", TileEditableBlock.class).setResistance(60000f).setFlammable(false).setCreativeTab(Blockcraftery.tab));
editable_fence_reinforced = event.addBlock(new BlockEditableFence(editable_block_reinforced, SoundType.WOOD, 1.0f, "editable_fence_reinforced", TileEditableBlock.class).setResistance(60000f).setFlammable(false).setCreativeTab(Blockcraftery.tab));

editable_trap_door = event.addBlock(new BlockEditableTrapDoor(editable_block, SoundType.WOOD, 1.0f, "editable_trap_door", TileEditableBlock.class).setResistance(0f).setFlammable(true).setModelCustom(true).setCreativeTab(Blockcraftery.tab));
editable_trap_door_reinforced = event.addBlock(new BlockEditableTrapDoor(editable_block_reinforced, SoundType.WOOD, 1.0f, "editable_trap_door_reinforced", TileEditableBlock.class).setResistance(6000f).setFlammable(false).setModelCustom(true).setCreativeTab(Blockcraftery.tab));
}

@SideOnly(Side.CLIENT)
Expand Down Expand Up @@ -90,5 +97,8 @@ public void onRegisterRecipes(RegisterModRecipesEvent event) {
RecipeRegistry.registerShapedMirrored(event.getRegistry(), "editable_inner_corner_reinforced", new ItemStack(editable_inner_corner_reinforced, 2), " S", "SS", 'S', editable_slant_reinforced);
RecipeRegistry.registerShapeless(event.getRegistry(), "editable_outer_corner_reinforced", new ItemStack(editable_outer_corner_reinforced, 2), editable_slant_reinforced);
RecipeRegistry.registerShapedMirrored(event.getRegistry(), "editable_fence_reinforced", new ItemStack(editable_fence_reinforced, 6), "SWS", "SWS", 'S', editable_block_reinforced, 'W', "stickWood");

RecipeRegistry.registerShaped(event.getRegistry(), "editable_trap_door", new ItemStack(editable_trap_door, 2), "WWW", "SSS", "SSS", 'S', editable_block, 'W', "stickWood");
RecipeRegistry.registerShaped(event.getRegistry(), "editable_trap_door_reinforced", new ItemStack(editable_trap_door_reinforced, 2), "WWW", "SSS", "SSS", 'S', editable_block_reinforced, 'W', "stickWood");
}
}
138 changes: 138 additions & 0 deletions src/main/java/epicsquid/blockcraftery/block/BlockEditableTrapDoor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package epicsquid.blockcraftery.block;

import javax.annotation.Nonnull;

import epicsquid.blockcraftery.model.BakedModelEditableTrapDoor;
import epicsquid.blockcraftery.model.BakedModelEditableWall;
import epicsquid.blockcraftery.tile.TileEditableBlock;
import epicsquid.mysticallib.block.BlockTETrapDoorBase;
import epicsquid.mysticallib.model.block.BakedModelBlock;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import static epicsquid.blockcraftery.block.BlockEditableCube.LIGHT;

public class BlockEditableTrapDoor extends BlockTETrapDoorBase implements IEditableBlock {

public BlockEditableTrapDoor(@Nonnull Block block, @Nonnull SoundType type, float hardness, @Nonnull String name,
@Nonnull Class<? extends TileEntity> teClass) {
super(block, type, hardness, name, teClass);
setModelCustom(true);
setLightOpacity(0);
setOpacity(false);
setDefaultState(blockState.getBaseState().withProperty(LIGHT, false));
}

@Override
public int getLightOpacity(IBlockState state, IBlockAccess world, BlockPos pos) {
if (getParent() != null) {
return super.getLightOpacity(state, world, pos);
}
return super.getLightOpacity(state, world, pos);
}

@Override
@Nonnull
public IBlockState getStateFromMeta(int meta) {
return getDefaultState().withProperty(LIGHT, meta == 1);
}

@Override
public int getMetaFromState(@Nonnull IBlockState state) {
return (state.getValue(LIGHT) ? 1 : 0);
}

@Override
public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos) {
return state.getValue(LIGHT) ? 15 : 0;
}

@SideOnly(Side.CLIENT)
@Override
public boolean canRenderInLayer(@Nonnull IBlockState state, @Nonnull BlockRenderLayer layer) {
return true;
}

@Override
@Nonnull
protected BlockStateContainer createBlockState() {
IProperty[] listedProperties = new IProperty[] { FACING, OPEN, HALF, LIGHT };
IUnlistedProperty[] unlistedProperties = new IUnlistedProperty[] { STATEPROP };
return new ExtendedBlockState(this, listedProperties, unlistedProperties);
}

@Override
@Nonnull
public IBlockState getExtendedState(@Nonnull IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos) {
TileEntity t = world.getTileEntity(pos);
IBlockState actual = getActualState(state, world, pos);
if (t instanceof TileEditableBlock && actual instanceof IExtendedBlockState) {
return ((IExtendedBlockState) actual).withProperty(STATEPROP, ((TileEditableBlock) t).state);
}
return state;
}

private static final UnlistedPropertyState STATEPROP = new UnlistedPropertyState();

public static class UnlistedPropertyState implements IUnlistedProperty<IBlockState> {

@Override
@Nonnull
public String getName() {
return "stateprop";
}

@Override
public boolean isValid(@Nonnull IBlockState value) {
return true;
}

@Override
@Nonnull
public Class<IBlockState> getType() {
return IBlockState.class;
}

@Override
@Nonnull
public String valueToString(@Nonnull IBlockState value) {
return value.toString();
}
}

@Override
public boolean doesSideBlockRendering(@Nonnull IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull EnumFacing side) {
return false;
}

@Override
public boolean isSideSolid(@Nonnull IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull EnumFacing side) {
return false;
}

@Override
@Nonnull
protected Class<? extends BakedModelBlock> getModelClass() {
return BakedModelEditableTrapDoor.class;
}

@Override
@Nonnull
public IUnlistedProperty<IBlockState> getStateProperty() {
return STATEPROP;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package epicsquid.blockcraftery.model;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

import javax.vecmath.Matrix4f;

import org.apache.commons.lang3.tuple.Pair;

import epicsquid.mysticallib.model.CustomModelBase;
import epicsquid.mysticallib.model.DefaultTransformations;
import epicsquid.mysticallib.model.ModelUtil;
import epicsquid.mysticallib.model.parts.Cube;
import epicsquid.mysticallib.struct.Vec4f;
import net.minecraft.block.BlockTrapDoor;
import net.minecraft.block.BlockWall;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.block.model.ItemOverrideList;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.model.IModelState;

public class BakedModelEditableTrapDoor extends BakedModelEditable {
public static Map<String, List<BakedQuad>> data = new HashMap<>();

private Cube cube_down;

public BakedModelEditableTrapDoor(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter,
CustomModelBase model) {
super(state, format, bakedTextureGetter, model);
TextureAtlasSprite[] texes = new TextureAtlasSprite[] { texwest, texeast, texdown, texup, texnorth, texsouth };
cube_down = ModelUtil.makeCube(format, 0, 0, 0, 1, 0.1875, 1, null, texes, 0).setNoCull(EnumFacing.DOWN);
}

@Override
public void addGeometry(List<BakedQuad> quads, EnumFacing side, IBlockState state, TextureAtlasSprite[] texes, int tintIndex) {
Cube cube_down, cube_up, cube_east, cube_west, cube_south, cube_north;
cube_down = ModelUtil.makeCube(format, 0, 0, 0, 1, 0.1875, 1, null, texes, 0).setNoCull(EnumFacing.DOWN);
cube_up = ModelUtil.makeCube(format, 0, 0.8125, 0, 1, 0.1875, 1, null, texes, 0).setNoCull(EnumFacing.UP);
cube_west = ModelUtil.makeCube(format, 0.8125, 0, 0, 0.1875, 1, 1, null, texes, 0).setNoCull(EnumFacing.WEST);
cube_east = ModelUtil.makeCube(format, 0, 0, 0, 0.1875, 1, 1, null, texes, 0).setNoCull(EnumFacing.EAST);
cube_north = ModelUtil.makeCube(format, 0, 0, 0.8125, 1, 1, 0.1875, null, texes, 0).setNoCull(EnumFacing.NORTH);
cube_south = ModelUtil.makeCube(format, 0, 0, 0, 1, 1, 0.1875, null, texes, 0).setNoCull(EnumFacing.SOUTH);
BlockTrapDoor.DoorHalf half = state.getValue(BlockTrapDoor.HALF);
boolean open = state.getValue(BlockTrapDoor.OPEN);
if (!open) {
if (half == BlockTrapDoor.DoorHalf.BOTTOM) {
cube_down.addToList(quads, side);
} else {
cube_up.addToList(quads, side);
}
} else {
switch (state.getValue(BlockTrapDoor.FACING)) {
case EAST:
cube_east.addToList(quads, side);
break;
case SOUTH:
cube_south.addToList(quads, side);
break;
case WEST:
cube_west.addToList(quads, side);
break;
case NORTH:
cube_north.addToList(quads, side);
break;
}
}
}

@Override
public boolean isAmbientOcclusion() {
return true;
}

@Override
public boolean isGui3d() {
return true;
}

@Override
public boolean isBuiltInRenderer() {
return false;
}

@Override
public TextureAtlasSprite getParticleTexture() {
return particle;
}

@Override
public ItemOverrideList getOverrides() {
return new ItemOverrideList(Arrays.asList());
}

@Override
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType type) {
Matrix4f matrix = null;
if (DefaultTransformations.blockTransforms.containsKey(type)) {
matrix = DefaultTransformations.blockTransforms.get(type).getMatrix();
return Pair.of(this, matrix);
}
return net.minecraftforge.client.ForgeHooksClient.handlePerspective(this, type);
}

@Override
public void addItemModel(List<BakedQuad> quads, EnumFacing side) {
cube_down.addToList(quads, side);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"custom": {
"model": "blockcraftery:editable_trap_door"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"custom": {
"model": "blockcraftery:editable_trap_door_reinforced"
}
}
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/blockcraftery/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ tile.editable_inner_corner.name=Framed Inner Corner
tile.editable_outer_corner.name=Framed Outer Corner
tile.editable_wall.name=Framed Wall
tile.editable_fence.name=Framed Fence
tile.editable_trap_door.name=Framed Trapdoor

tile.editable_block_reinforced.name=Reinforced Framed Block
tile.editable_slab_reinforced.name=Reinforced Framed Slab
Expand All @@ -16,4 +17,5 @@ tile.editable_slant_reinforced.name=Reinforced Framed Slant
tile.editable_inner_corner_reinforced.name=Reinforced Framed Inner Corner
tile.editable_outer_corner_reinforced.name=Reinforced Framed Outer Corner
tile.editable_wall_reinforced.name=Reinforced Framed Wall
tile.editable_fence_reinforced.name=Reinforced Framed Fence
tile.editable_fence_reinforced.name=Reinforced Framed Fence
tile.editable_trap_door_reinforced.name=Reinforced Framed Trapdoor

0 comments on commit ba7ae6a

Please sign in to comment.