Commit 815ef945 authored by SilverDavid's avatar SilverDavid

Working on a thing. Get excited.

parent e66d5afc
......@@ -27,7 +27,7 @@ minecraft {
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
property 'forge.logging.console.level', 'debug'
property 'forge.logging.console.level', 'info'
mods {
rediscovered {
......@@ -41,7 +41,7 @@ minecraft {
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
property 'forge.logging.console.level', 'debug'
property 'forge.logging.console.level', 'info'
mods {
rediscovered {
......
......@@ -3,6 +3,7 @@ package com.legacy.rediscovered;
import com.legacy.rediscovered.block.RediscoveredBlocks;
import com.legacy.rediscovered.client.RediscoveredClientEvents;
import com.legacy.rediscovered.client.RediscoveredEntityRendering;
import com.legacy.rediscovered.client.RediscoveredTileEntityRendering;
import com.legacy.rediscovered.entity.RediscoveredEntityTypes;
import com.legacy.rediscovered.event.RediscoveredEvents;
......@@ -73,6 +74,7 @@ public class RediscoveredMod
public void clientInit(FMLClientSetupEvent event)
{
RediscoveredEntityRendering.init();
RediscoveredTileEntityRendering.init();
MinecraftForge.EVENT_BUS.register(new RediscoveredClientEvents());
}
}
......@@ -4,6 +4,7 @@ import com.legacy.rediscovered.block.RediscoveredBlocks;
import com.legacy.rediscovered.client.RediscoveredSounds;
import com.legacy.rediscovered.entity.RediscoveredEntityTypes;
import com.legacy.rediscovered.item.RediscoveredItems;
import com.legacy.rediscovered.tile_entity.RediscoveredTileEntities;
import com.legacy.rediscovered.world.RediscoveredChunkGeneratorTypes;
import com.legacy.rediscovered.world.biome.RediscoveredBiomes;
import com.legacy.rediscovered.world.biome.feature.RediscoveredFeatures;
......@@ -12,6 +13,7 @@ import com.legacy.rediscovered.world.dimension.RediscoveredDimensions;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.SoundEvent;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.ChunkGeneratorType;
......@@ -38,7 +40,13 @@ public class RediscoveredRegistry
{
RediscoveredBlocks.init(event);
}
@SubscribeEvent
public static void registerTileEntityTypes(Register<TileEntityType<?>> event)
{
RediscoveredTileEntities.init(event);
}
@SubscribeEvent
public static void registerItems(Register<Item> event)
{
......
package com.legacy.rediscovered.block;
import java.util.Random;
import javax.annotation.Nullable;
import com.legacy.rediscovered.tile_entity.GearTileEntity;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.ContainerBlock;
import net.minecraft.block.material.PushReaction;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.pathfinding.PathType;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer.Builder;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.World;
public class GearBlock extends ContainerBlock
{
public static enum EnumFaces
{
//@formatter:off
NORTH(Direction.NORTH, BlockStateProperties.NORTH, Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 1.0D)),
SOUTH(Direction.SOUTH, BlockStateProperties.SOUTH, Block.makeCuboidShape(0.0D, 0.0D, 15.0D, 16.0D, 16.0D, 16.0D)),
EAST(Direction.EAST, BlockStateProperties.EAST, Block.makeCuboidShape(15.0D, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D)),
WEST(Direction.WEST, BlockStateProperties.WEST, Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 1.0D, 16.0D, 16.0D)),
UP(Direction.UP, BlockStateProperties.UP, Block.makeCuboidShape(0.0D, 15.0D, 0.0D, 16.0D, 16.0D, 16.0D)),
DOWN(Direction.DOWN, BlockStateProperties.DOWN, Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 1.0D, 16.0D));
//@formatter:on
public final Direction direction;
public final BooleanProperty face;
public final VoxelShape shape;
EnumFaces(Direction direction, BooleanProperty face, VoxelShape shape)
{
this.direction = direction;
this.face = face;
this.shape = shape;
}
public static EnumFaces get(Direction direction)
{
for (EnumFaces enumFace : EnumFaces.values())
if (direction == enumFace.direction)
return enumFace;
return null;
}
}
public GearBlock(Properties properties)
{
super(properties);
BlockState defaultState = this.getDefaultState();
for (EnumFaces enumFace : EnumFaces.values())
defaultState = defaultState.with(enumFace.face, false);
this.setDefaultState(defaultState);
}
@Override
public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos)
{
for (EnumFaces enumFace : EnumFaces.values())
if (state.get(enumFace.face) == true && !isSolid(worldIn, pos, enumFace.direction.getOpposite()))
return false;
return true;
}
public static boolean isSolid(IWorldReader world, BlockPos pos, Direction direction)
{
BlockPos offsetPos = pos.offset(direction.getOpposite());
return world.getBlockState(offsetPos).func_224755_d(world, offsetPos, direction);
}
@Override
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving)
{
worldIn.getPendingBlockTicks().scheduleTick(pos, this, 0);
if (worldIn.getTileEntity(pos) instanceof GearTileEntity)
{
GearTileEntity tile = (GearTileEntity) worldIn.getTileEntity(pos);
if (worldIn.isBlockPowered(pos))
{
for (Direction direction : Direction.values())
{
tile.setPower(direction, worldIn.getRedstonePower(pos, direction));
System.out.println(worldIn.getRedstonePower(pos, direction));
}
}
else
{
for (Direction direction : Direction.values())
tile.setPower(direction, 0);
}
}
state.updateNeighbors(worldIn, pos, 3);
}
@Override
public void tick(BlockState state, World worldIn, BlockPos pos, Random random)
{
for (EnumFaces enumFace : EnumFaces.values())
{
if (state.get(enumFace.face) == true && !isSolid(worldIn, pos, enumFace.direction.getOpposite()))
{
spawnDrops(this.getDefaultState().with(enumFace.face, true), worldIn, pos);
worldIn.destroyBlock(pos, false);
worldIn.setBlockState(pos, removeFace(state, enumFace));
}
}
}
public BlockState removeFace(BlockState state, EnumFaces enumFaceIn)
{
state = state.with(enumFaceIn.face, false);
boolean hasAFace = false;
for (EnumFaces enumFace : EnumFaces.values())
if (state.get(enumFace.face))
hasAFace = true;
return hasAFace ? state : Blocks.AIR.getDefaultState();
}
@Override
@Nullable
public BlockState getStateForPlacement(BlockItemUseContext context)
{
BlockState oldState = context.getWorld().getBlockState(context.getPos());
if (oldState.getBlock() == this)
return oldState.with(EnumFaces.get(context.getFace().getOpposite()).face, true);
else if (this.getDefaultState().isValidPosition(context.getWorld(), context.getPos()))
return this.getDefaultState().with(EnumFaces.get(context.getFace().getOpposite()).face, true);
else
return null;
}
@Override
public boolean isReplaceable(BlockState state, BlockItemUseContext useContext)
{
if (useContext.getItem().getItem() == this.asItem() && state.get(EnumFaces.get(useContext.getFace().getOpposite()).face) == false)
if (useContext.replacingClickedOnBlock())
return true;
else
return true;
else
return false;
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context)
{
VoxelShape shape = VoxelShapes.empty();
for (EnumFaces enumFace : EnumFaces.values())
if (state.get(enumFace.face) == true)
shape = VoxelShapes.or(shape, enumFace.shape);
return shape;
}
@Override
public BlockRenderLayer getRenderLayer()
{
return BlockRenderLayer.CUTOUT;
}
@Override
public BlockRenderType getRenderType(BlockState state)
{
return BlockRenderType.ENTITYBLOCK_ANIMATED;
}
@Override
public boolean allowsMovement(BlockState state, IBlockReader worldIn, BlockPos pos, PathType type)
{
return true;
}
@Override
public PushReaction getPushReaction(BlockState state)
{
return PushReaction.DESTROY;
}
@Override
public boolean causesSuffocation(BlockState state, IBlockReader worldIn, BlockPos pos)
{
return false;
}
@Override
public boolean propagatesSkylightDown(BlockState state, IBlockReader reader, BlockPos pos)
{
return true;
}
@Override
public boolean isNormalCube(BlockState state, IBlockReader worldIn, BlockPos pos)
{
return false;
}
@Override
protected void fillStateContainer(Builder<Block, BlockState> builder)
{
for (EnumFaces enumFace : EnumFaces.values())
builder.add(enumFace.face);
}
@Override
public TileEntity createNewTileEntity(IBlockReader worldIn)
{
return new GearTileEntity();
}
@Override
public boolean hasComparatorInputOverride(BlockState state)
{
return true;
}
@Override
public int getComparatorInputOverride(BlockState state, World worldIn, BlockPos pos)
{
int power = 0;
TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof GearTileEntity)
for (int p : ((GearTileEntity) tile).getPowers())
if (p > power)
power = p;
return power;
}
}
......@@ -15,7 +15,6 @@ import net.minecraft.block.FlowerBlock;
import net.minecraft.block.LeavesBlock;
import net.minecraft.block.LogBlock;
import net.minecraft.block.PressurePlateBlock;
import net.minecraft.block.RedstoneWireBlock;
import net.minecraft.block.SaplingBlock;
import net.minecraft.block.SlabBlock;
import net.minecraft.block.SoundType;
......@@ -44,7 +43,7 @@ public class RediscoveredBlocks
public static Block rose, paeonia, empty_rose_bush, empty_peony_bush, potted_rose, potted_paeonia,
potted_cherry_sapling;
public static Block dirt_slab, spikes, gear, lantern;
public static Block dirt_slab, spikes, rotational_converter, gear, lantern;
public static Block oak_table, oak_chair, spruce_table, spruce_chair, birch_table, birch_chair, jungle_table,
jungle_chair, acacia_table, acacia_chair, dark_oak_table, dark_oak_chair, cherry_table, cherry_chair;
......@@ -91,7 +90,8 @@ public class RediscoveredBlocks
crying_obsidian = register("crying_obsidian", new Block(Block.Properties.from(Blocks.OBSIDIAN)));
spikes = register("spikes", new SpikeBlock(Block.Properties.from(Blocks.OAK_PLANKS)));
gear = register("gear", new RedstoneWireBlock(Block.Properties.from(Blocks.REDSTONE_WIRE).sound(SoundType.METAL)));
rotational_converter = register("rotational_converter", new RotationalConverterBlock(Block.Properties.from(Blocks.OBSERVER)));
gear = register("gear", new GearBlock(Block.Properties.create(Material.MISCELLANEOUS).doesNotBlockMovement().hardnessAndResistance(0).sound(SoundType.METAL)));
lantern = register("lantern", new ClassicLanternBlock(Block.Properties.from(Blocks.LANTERN).sound(SoundType.METAL)), null);
oak_chair = register("oak_chair", new ChairBlock(Block.Properties.from(Blocks.OAK_PLANKS)), decorTab);
......
package com.legacy.rediscovered.block;
import java.util.Random;
import com.legacy.rediscovered.tile_entity.GearTileEntity;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.DirectionalBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.EnumProperty;
import net.minecraft.state.StateContainer.Builder;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
public class RotationalConverterBlock extends DirectionalBlock
{
public static enum Mode implements IStringSerializable
{
GEAR_TO_REDSTONE, REDSTONE_TO_GEAR;
@Override
public String getName()
{
return this.toString().toLowerCase();
}
}
public static final EnumProperty<Mode> MODE = EnumProperty.create("mode", Mode.class);
public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
public RotationalConverterBlock(Properties properties)
{
super(properties);
}
@Override
public BlockState rotate(BlockState state, Rotation rot)
{
return state.with(FACING, rot.rotate(state.get(FACING)));
}
@Override
public BlockState mirror(BlockState state, Mirror mirrorIn)
{
return state.rotate(mirrorIn.toRotation(state.get(FACING)));
}
//TODO
// When you get powered by redstone, yell at the gears or vis versa
@Override
public void tick(BlockState state, World worldIn, BlockPos pos, Random random)
{
if (state.get(POWERED))
{
worldIn.setBlockState(pos, state.with(POWERED, Boolean.valueOf(false)), 2);
}
else
{
worldIn.setBlockState(pos, state.with(POWERED, Boolean.valueOf(true)), 2);
worldIn.getPendingBlockTicks().scheduleTick(pos, this, 2);
}
this.updateNeighborsInFront(worldIn, pos, state);
}
//TODO
// Turn on when you get placed
@Override
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos)
{
/*if (stateIn.get(FACING) == facing && worldIn.reds && !stateIn.get(POWERED))
{
this.startSignal(worldIn, currentPos);
}*/
return stateIn;
}
private void startSignal(IWorld worldIn, BlockPos pos)
{
if (!worldIn.isRemote() && !worldIn.getPendingBlockTicks().isTickScheduled(pos, this))
{
worldIn.getPendingBlockTicks().scheduleTick(pos, this, 2);
}
}
protected void updateNeighborsInFront(World worldIn, BlockPos pos, BlockState state)
{
Direction direction = state.get(FACING);
BlockPos blockpos = pos.offset(direction.getOpposite());
worldIn.neighborChanged(blockpos, this, pos);
worldIn.notifyNeighborsOfStateExcept(blockpos, this, direction);
}
@Override
public boolean canProvidePower(BlockState state)
{
return state.get(MODE) == Mode.GEAR_TO_REDSTONE;
}
@Override
public int getStrongPower(BlockState state, IBlockReader access, BlockPos pos, Direction side)
{
return state.getWeakPower(access, pos, side);
}
@Override
public int getWeakPower(BlockState state, IBlockReader access, BlockPos pos, Direction side)
{
if (state.get(MODE) == Mode.GEAR_TO_REDSTONE && state.get(POWERED) && state.get(FACING) == side)
{
if (access.getTileEntity(pos.offset(side.getOpposite())) instanceof GearTileEntity)
{
return ((GearTileEntity) access.getTileEntity(pos.offset(side.getOpposite()))).getPower(side.getOpposite());
}
return 0;
}
else
return 0;
}
@Override
public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving)
{
if (state.getBlock() != oldState.getBlock())
{
if (!worldIn.isRemote() && state.get(POWERED) && !worldIn.getPendingBlockTicks().isTickScheduled(pos, this))
{
BlockState blockstate = state.with(POWERED, Boolean.valueOf(false));
worldIn.setBlockState(pos, blockstate, 18);
this.updateNeighborsInFront(worldIn, pos, blockstate);
}
}
}
@Override
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving)
{
if (state.getBlock() != newState.getBlock())
{
if (!worldIn.isRemote && state.get(POWERED) && worldIn.getPendingBlockTicks().isTickScheduled(pos, this))
{
this.updateNeighborsInFront(worldIn, pos, state.with(POWERED, Boolean.valueOf(false)));
}
}
}
@Override
public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit)
{
if (!worldIn.isRemote())
{
worldIn.setBlockState(pos, state.cycle(MODE));
float f = state.get(POWERED) ? 0.6F : 0.5F;
worldIn.playSound((PlayerEntity) null, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 0.3F, f);
this.updateNeighbors(state, worldIn, pos);
}
return true;
}
private void updateNeighbors(BlockState state, World worldIn, BlockPos pos)
{
worldIn.notifyNeighborsOfStateChange(pos, this);
worldIn.notifyNeighborsOfStateChange(pos.offset(state.get(DirectionalBlock.FACING)), this);
worldIn.notifyNeighborsOfStateChange(pos.offset(state.get(DirectionalBlock.FACING).getOpposite()), this);
}
@Override
public BlockState getStateForPlacement(BlockItemUseContext context)
{
return this.getDefaultState().with(FACING, context.getNearestLookingDirection().getOpposite().getOpposite());
}
@Override
protected void fillStateContainer(Builder<Block, BlockState> builder)
{
builder.add(MODE, POWERED, DirectionalBlock.FACING);
}
}
package com.legacy.rediscovered.client;
import com.legacy.rediscovered.client.render.tile_entity.GearRenderer;
import com.legacy.rediscovered.tile_entity.GearTileEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.client.registry.ClientRegistry;
@OnlyIn(Dist.CLIENT)
public class RediscoveredTileEntityRendering
{
public static void init()
{
ClientRegistry.bindTileEntitySpecialRenderer(GearTileEntity.class, new GearRenderer());
}
}
package com.legacy.rediscovered.client.render.model;
import net.minecraft.client.renderer.entity.model.RendererModel;
import net.minecraft.client.renderer.model.Model;
public class GearModel extends Model
{
RendererModel down;
public GearModel()
{
this.textureHeight = 16;
this.textureWidth = 16;
down = new RendererModel(this, 0, 0);
down.addBox(-8, -7, -8, 16, 0, 16);
down.setRotationPoint(0, 0, 0);
down.setTextureSize(16, 16);
}
public void render()
{
this.down.render(1.0F);
}
}
package com.legacy.rediscovered.client.render.tile_entity;
import com.legacy.rediscovered.RediscoveredMod;
import com.legacy.rediscovered.block.GearBlock.EnumFaces;
import com.legacy.rediscovered.client.render.model.GearModel;
import com.legacy.rediscovered.tile_entity.GearTileEntity;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
public class GearRenderer extends TileEntityRenderer<GearTileEntity>
{
private static final GearModel MODEL = new GearModel();
private static final ResourceLocation TEXTURE = RediscoveredMod.locate("textures/block/gear.png");
@Override
public void render(GearTileEntity tile, double x, double y, double z, float partialTicks, int destroyStage)
{
GlStateManager.pushMatrix();
this.bindTexture(TEXTURE);
GlStateManager.translated(x + 0.5, y + 0.5, z + 0.5);
GlStateManager.disableLighting();
double scale = 1d / 16d;
GlStateManager.scaled(scale, scale, scale);
for (EnumFaces enumFace : EnumFaces.values())
{
GlStateManager.pushMatrix();
switch (enumFace)
{
case NORTH:
GlStateManager.rotated(90, 1, 0, 0);
break;
case SOUTH:
GlStateManager.rotated(-90, 1, 0, 0);
break;
case EAST:
GlStateManager.rotated(90, 0, 0, 1);
break;
case WEST:
GlStateManager.rotated(-90, 0, 0, 1);
break;
case UP:
GlStateManager.rotated(180, 1, 0, 0);
break;
default:
break;
}
GlStateManager.rotated(tile.getAngle(enumFace.direction), 0, 1, 0);
if (tile.getBlockState().get(enumFace.face))
MODEL.render();
GlStateManager.popMatrix();
}
GlStateManager.enableLighting();
GlStateManager.popMatrix();
}
}
package com.legacy.rediscovered.tile_entity;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
public class GearTileEntity extends TileEntity implements ITickableTileEntity