forked from MysticMods/Blockcraftery
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
284 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
src/main/java/epicsquid/blockcraftery/block/BlockEditableTrapDoor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
118 changes: 118 additions & 0 deletions
118
src/main/java/epicsquid/blockcraftery/model/BakedModelEditableTrapDoor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/resources/assets/blockcraftery/blockstates/editable_trap_door.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"variants": { | ||
"custom": { | ||
"model": "blockcraftery:editable_trap_door" | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/resources/assets/blockcraftery/blockstates/editable_trap_door_reinforced.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"variants": { | ||
"custom": { | ||
"model": "blockcraftery:editable_trap_door_reinforced" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters