...
 
Commits (6)
......@@ -96,14 +96,12 @@ public class ChairBlock extends HorizontalBlock implements IWaterLoggable
return BlockRenderLayer.CUTOUT;
}
@SuppressWarnings("deprecation")
@Override
public IFluidState getFluidState(BlockState state)
{
return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state);
return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : Fluids.EMPTY.getDefaultState();
}
@SuppressWarnings("deprecation")
@Override
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos)
{
......@@ -112,7 +110,7 @@ public class ChairBlock extends HorizontalBlock implements IWaterLoggable
worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn));
}
return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos);
return stateIn;
}
@Override
......
......@@ -24,6 +24,7 @@ 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.IWorldReader;
import net.minecraft.world.World;
public class RotationalConverterBlock extends DirectionalBlock
......@@ -45,88 +46,102 @@ public class RotationalConverterBlock extends DirectionalBlock
public RotationalConverterBlock(Properties properties)
{
super(properties);
this.setDefaultState(this.getDefaultState().with(POWERED, false).with(MODE, Mode.GEAR_TO_REDSTONE).with(DirectionalBlock.FACING, Direction.NORTH));
}
// Makes it not conduct redstone through it, just like a piston. Makes powering
// it way easier.
@Override
public boolean isNormalCube(BlockState state, IBlockReader worldIn, BlockPos pos)
{
return false;
}
// Structure blocks and maybe other mods could use this.
@Override
public BlockState rotate(BlockState state, Rotation rot)
{
return state.with(FACING, rot.rotate(state.get(FACING)));
}
// Structure blocks and maybe other mods could use this.
@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
// 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))
System.out.println(pos);
Direction facing = state.get(FACING);
if (state.get(MODE) == Mode.REDSTONE_TO_GEAR)
{
worldIn.setBlockState(pos, state.with(POWERED, Boolean.valueOf(false)), 2);
boolean flag = worldIn.isSidePowered(pos.offset(facing.getOpposite()), facing.getOpposite()) != state.get(POWERED);
if (flag)
worldIn.setBlockState(pos, state.with(POWERED, worldIn.isBlockPowered(pos)), 3);
if (worldIn.getTileEntity(pos.offset(facing)) instanceof GearTileEntity)
{
if (worldIn.isBlockPowered(pos))
((GearTileEntity) worldIn.getTileEntity(pos.offset(facing))).spin(worldIn, pos.offset(facing), facing.getOpposite(), 15, worldIn.getRedstonePower(pos.offset(facing.getOpposite()), facing.getOpposite()));
else
((GearTileEntity) worldIn.getTileEntity(pos.offset(facing))).stop(worldIn, pos.offset(facing), facing.getOpposite(), 15);
}
}
else
{
worldIn.setBlockState(pos, state.with(POWERED, Boolean.valueOf(true)), 2);
worldIn.getPendingBlockTicks().scheduleTick(pos, this, 2);
if (worldIn.getTileEntity(pos.offset(facing)) instanceof GearTileEntity)
{
GearTileEntity gear = ((GearTileEntity) worldIn.getTileEntity(pos.offset(facing)));
worldIn.setBlockState(pos, state.with(POWERED, gear.getPower(facing.getOpposite()) != 0), 3);
}
}
this.updateNeighborsInFront(worldIn, pos, state);
}
//TODO
// Turn on when you get placed
// Update this block when it's neighbors change. Useful for changing it based on
// redstone signals and gears.
@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)
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving)
{
if (!worldIn.isRemote() && !worldIn.getPendingBlockTicks().isTickScheduled(pos, this))
{
if (!worldIn.isRemote())
worldIn.getPendingBlockTicks().scheduleTick(pos, this, 2);
}
}
protected void updateNeighborsInFront(World worldIn, BlockPos pos, BlockState state)
// Update when you get placed
@Override
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos)
{
Direction direction = state.get(FACING);
BlockPos blockpos = pos.offset(direction.getOpposite());
worldIn.neighborChanged(blockpos, this, pos);
worldIn.notifyNeighborsOfStateExcept(blockpos, this, direction);
return stateIn;
}
// Make the block emit a redstone signal, only when in GEAR_TO_REDSTONE mode.
@Override
public boolean canProvidePower(BlockState state)
{
return state.get(MODE) == Mode.GEAR_TO_REDSTONE;
}
// Calls getWeakPower
@Override
public int getStrongPower(BlockState state, IBlockReader access, BlockPos pos, Direction side)
{
return state.getWeakPower(access, pos, side);
}
// Get's the power strength from the connected to it when in the correct mode. 0
// otherwise.
@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)
if (access.getTileEntity(pos.offset(side)) instanceof GearTileEntity)
{
return ((GearTileEntity) access.getTileEntity(pos.offset(side.getOpposite()))).getPower(side.getOpposite());
return Math.abs(((GearTileEntity) access.getTileEntity(pos.offset(side))).getPower(side.getOpposite()));
}
return 0;
}
......@@ -134,6 +149,13 @@ public class RotationalConverterBlock extends DirectionalBlock
return 0;
}
// Only check for weak redstone power on the correct side in the correct mode
@Override
public boolean shouldCheckWeakPower(BlockState state, IWorldReader world, BlockPos pos, Direction side)
{
return side == state.get(FACING).getOpposite() && state.get(MODE) == Mode.REDSTONE_TO_GEAR;
}
@Override
public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving)
{
......@@ -143,10 +165,12 @@ public class RotationalConverterBlock extends DirectionalBlock
{
BlockState blockstate = state.with(POWERED, Boolean.valueOf(false));
worldIn.setBlockState(pos, blockstate, 18);
this.updateNeighborsInFront(worldIn, pos, blockstate);
this.updateNeighborsOnFaces(worldIn, pos, blockstate);
}
}
state.updateNeighbors(worldIn, pos, 3);
}
@Override
......@@ -156,15 +180,21 @@ public class RotationalConverterBlock extends DirectionalBlock
{
if (!worldIn.isRemote && state.get(POWERED) && worldIn.getPendingBlockTicks().isTickScheduled(pos, this))
{
this.updateNeighborsInFront(worldIn, pos, state.with(POWERED, Boolean.valueOf(false)));
this.updateNeighborsOnFaces(worldIn, pos, state.with(POWERED, Boolean.valueOf(false)));
}
}
state.updateNeighbors(worldIn, pos, 3);
}
@Override
public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit)
{
// Let players place the gear on the gear side
if (player.getHeldItem(handIn).getItem() == RediscoveredBlocks.gear.asItem() && state.get(FACING) == hit.getFace())
return false;
// Change the mode of this to the opposite
if (!worldIn.isRemote())
{
worldIn.setBlockState(pos, state.cycle(MODE));
......@@ -176,6 +206,16 @@ public class RotationalConverterBlock extends DirectionalBlock
return true;
}
protected void updateNeighborsOnFaces(World worldIn, BlockPos pos, BlockState state)
{
for (Direction direction : new Direction[] { state.get(FACING), state.get(FACING).getOpposite() })
{
BlockPos blockpos = pos.offset(direction.getOpposite());
worldIn.neighborChanged(blockpos, this, pos);
worldIn.notifyNeighborsOfStateExcept(blockpos, this, direction);
}
}
private void updateNeighbors(BlockState state, World worldIn, BlockPos pos)
{
worldIn.notifyNeighborsOfStateChange(pos, this);
......
......@@ -128,7 +128,7 @@ public class SpikeBlock extends DirectionalBlock implements IWaterLoggable
else
{
IFluidState ifluidstate = context.getWorld().getFluidState(blockpos);
BlockState blockstate1 = this.getDefaultState().with(WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER)).with(FACING, context.getNearestLookingDirection().getOpposite());
BlockState blockstate1 = this.getDefaultState().with(WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER)).with(FACING, context.getFace());
return blockstate1;
}
}
......
......@@ -2,6 +2,7 @@ package com.legacy.rediscovered.block;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.IWaterLoggable;
import net.minecraft.fluid.Fluids;
import net.minecraft.fluid.IFluidState;
import net.minecraft.item.BlockItemUseContext;
......@@ -16,7 +17,7 @@ import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
public class TableBlock extends Block
public class TableBlock extends Block implements IWaterLoggable
{
private static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
private static final VoxelShape TABLE_SHAPE = VoxelShapes.or(Block.makeCuboidShape(2.0D, 0.0D, 12.0D, 4.0D, 9.0D, 14.0D), Block.makeCuboidShape(12.0D, 0.0D, 2.0D, 14.0D, 9.0D, 4.0D), Block.makeCuboidShape(12.0D, 0.0D, 12.0D, 14.0D, 9.0D, 14.0D), Block.makeCuboidShape(2.0D, 0.0D, 2.0D, 4.0D, 9.0D, 4.0D), Block.makeCuboidShape(2.0D, 9.0D, 2.0D, 14.0D, 11.0D, 14.0D));
......@@ -33,14 +34,12 @@ public class TableBlock extends Block
return TABLE_SHAPE;
}
@SuppressWarnings("deprecation")
@Override
public IFluidState getFluidState(BlockState state)
{
return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state);
return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : Fluids.EMPTY.getDefaultState();
}
@SuppressWarnings("deprecation")
@Override
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos)
{
......@@ -48,7 +47,7 @@ public class TableBlock extends Block
{
worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn));
}
return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos);
return stateIn;
}
@Override
......
......@@ -13,7 +13,7 @@ public class GearModel extends Model
this.textureWidth = 16;
down = new RendererModel(this, 0, 0);
down.addBox(-8, -7, -8, 16, 0, 16);
down.addBox(-8, -6.5f, -8, 16, 0, 16);
down.setRotationPoint(0, 0, 0);
down.setTextureSize(16, 16);
}
......
......@@ -7,7 +7,6 @@ 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>
......@@ -22,13 +21,13 @@ public class GearRenderer extends TileEntityRenderer<GearTileEntity>
this.bindTexture(TEXTURE);
GlStateManager.translated(x + 0.5, y + 0.5, z + 0.5);
GlStateManager.disableLighting();
double scale = 1d / 16d;
double scale = 1d / 14d;
GlStateManager.scaled(scale, scale, scale);
for (EnumFaces enumFace : EnumFaces.values())
{
GlStateManager.pushMatrix();
GlStateManager.rotated(0.25, 1, 0, 1);
switch (enumFace)
{
case NORTH:
......@@ -52,7 +51,7 @@ public class GearRenderer extends TileEntityRenderer<GearTileEntity>
GlStateManager.rotated(tile.getAngle(enumFace.direction), 0, 1, 0);
if (tile.getBlockState().get(enumFace.face))
if (tile.getBlockState().get(enumFace.face).exists())
MODEL.render();
GlStateManager.popMatrix();
......
......@@ -33,6 +33,7 @@ import net.minecraft.util.HandSide;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
......@@ -494,4 +495,10 @@ public class ScarecrowEntity extends LivingEntity
public void setItemStackToSlot(EquipmentSlotType slotIn, ItemStack stack)
{
}
@Override
public ItemStack getPickedResult(RayTraceResult target)
{
return new ItemStack(RediscoveredItems.scarecrow);
}
}
\ No newline at end of file
......@@ -49,9 +49,11 @@ import net.minecraft.entity.passive.horse.ZombieHorseEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.entity.projectile.AbstractArrowEntity;
import net.minecraft.entity.projectile.AbstractArrowEntity.PickupStatus;
import net.minecraft.entity.projectile.ArrowEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ArrowItem;
import net.minecraft.item.AxeItem;
import net.minecraft.item.BowItem;
import net.minecraft.item.ItemStack;
......@@ -76,7 +78,6 @@ import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.Tags;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.EntityMountEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
......@@ -310,40 +311,40 @@ public class RediscoveredEvents
{
try
{
PlayerEntity player = (PlayerEntity) event.getEntityLiving();
PlayerInventory inventory = player.inventory;
if ((inventory.getCurrentItem().getItem() instanceof BowItem || inventory.getCurrentItem().getItem().getClass().getName().equals("mod.torchbowmod.TorchBow")))
if (event.getItemStack().getItem() instanceof BowItem)
{
ItemStack par1ItemStack = inventory.getStackInSlot(inventory.currentItem);
boolean flag = player.isCreative() || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, par1ItemStack) > 0;
ItemStack chestSlot = player.getItemStackFromSlot(EquipmentSlotType.CHEST);
PlayerEntity player = (PlayerEntity) event.getEntityLiving();
ItemStack ammo = player.findAmmo(event.getItemStack());
ItemStack bow = event.getItemStack();
ItemStack chestPlate = player.getItemStackFromSlot(EquipmentSlotType.CHEST);
ItemStack ammo = player.findAmmo(bow);
if (chestSlot != null && chestSlot != ItemStack.EMPTY && RediscoveredTags.Items.QUIVERS.contains(chestSlot.getItem()))
if (chestPlate != null && !chestPlate.isEmpty() && RediscoveredTags.Items.QUIVERS.contains(chestPlate.getItem()))
{
if (player.inventory.hasTag(Tags.Items.ARROWS) || flag)
player.world.playSound(player, player.getPosition(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 0.8F));
AbstractArrowEntity arrowEntity = new ArrowEntity(player.world, player);
boolean infiniteFlag = false;
if (ammo.getItem() instanceof ArrowItem)
{
player.world.playSound(player, player.getPosition(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 0.8F));
arrowEntity = ((ArrowItem) ammo.getItem()).createArrow(event.getWorld(), ammo, player);
infiniteFlag = ((ArrowItem) ammo.getItem()).isInfinite(ammo, bow, player);
}
arrowEntity.setIsCritical(true);
arrowEntity.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.3F, 1.0F);
if (!player.world.isRemote)
{
if (infiniteFlag && (player.isCreative() || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, bow) > 0))
arrowEntity.pickupStatus = PickupStatus.CREATIVE_ONLY;
else
ammo.shrink(1);
ArrowEntity entityarrow = new ArrowEntity(player.world, player);
entityarrow.setIsCritical(true);
entityarrow.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.3F, 1.0F);
if (!player.world.isRemote)
bow.damageItem(1, player, (playerEntity) ->
{
if (!flag)
{
ammo.shrink(1);
}
else
{
entityarrow.pickupStatus = PickupStatus.CREATIVE_ONLY;
}
player.world.addEntity(entityarrow);
}
playerEntity.sendBreakAnimation(player.getActiveHand());
});
player.world.addEntity(arrowEntity);
}
event.setCanceled(true);
}
......
......@@ -3,6 +3,7 @@ package com.legacy.rediscovered.item;
import com.legacy.rediscovered.entity.PurpleArrowEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.AbstractArrowEntity;
import net.minecraft.item.ArrowItem;
import net.minecraft.item.Item;
......@@ -21,4 +22,10 @@ public class PurpleArrowItem extends ArrowItem
PurpleArrowEntity arrowentity = new PurpleArrowEntity(worldIn, shooter);
return arrowentity;
}
@Override
public boolean isInfinite(ItemStack stack, ItemStack bow, PlayerEntity player)
{
return net.minecraft.enchantment.EnchantmentHelper.getEnchantmentLevel(net.minecraft.enchantment.Enchantments.INFINITY, bow) >= 0;
}
}
\ No newline at end of file
......@@ -58,7 +58,7 @@ public class RediscoveredItems
raw_fish = register("raw_fish", new Item(new Item.Properties().group(ItemGroup.FOOD).food(Foods.COD)));
cooked_fish = register("cooked_fish", new Item(new Item.Properties().group(ItemGroup.FOOD).food(Foods.COOKED_COD)));
fish_bucket = register("fish_bucket", new FishBucketItem(RediscoveredEntityTypes.FISH, Fluids.WATER, (new Item.Properties()).maxStackSize(1).group(ItemGroup.MISC)));
fish_bucket = register("fish_bucket", new FishBucketItem(() -> RediscoveredEntityTypes.FISH, () -> Fluids.WATER, (new Item.Properties()).maxStackSize(1).group(ItemGroup.MISC)));
studded_helmet = register("studded_helmet", new ArmorItem(RediscoveredArmorMaterials.LEATHER_CHAIN, EquipmentSlotType.HEAD, new Item.Properties().group(ItemGroup.COMBAT)));
studded_chestplate = register("studded_chestplate", new ArmorItem(RediscoveredArmorMaterials.LEATHER_CHAIN, EquipmentSlotType.CHEST, new Item.Properties().group(ItemGroup.COMBAT)));
......
package com.legacy.rediscovered.tile_entity;
import com.legacy.rediscovered.block.GearBlock;
import com.legacy.rediscovered.block.RediscoveredBlocks;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
......@@ -7,40 +10,132 @@ import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class GearTileEntity extends TileEntity implements ITickableTileEntity
{
// down, up, north, south, west, east
private int[] powers = new int[] {0, 0, 0, 0, 0, 0};
private int[] angles = new int[] {0, 0, 0, 0, 0, 0};
// Array Order: down, up, north, south, west, east
// Powers stores redstone signal strength. Positive or negative relates to the
// direction the gear should spin, while the number itself is equal to signal
// strength. -15 - 15
private int[] powers = new int[] { 0, 0, 0, 0, 0, 0 };
// Stores the angles of each gear for their rotation animation. The angle is
// increased/decreased based on the powers array.
private int[] angles = new int[] { 0, 0, 0, 0, 0, 0 };
// Stores how far this gear is from the source. The first gear is 15, and all
// after decrease until 0. Gears with a distance of 0 will not spin.
private int[] distances = new int[] { 0, 0, 0, 0, 0, 0 };
public GearTileEntity()
{
super(RediscoveredTileEntities.gear);
}
public GearTileEntity(TileEntityType<?> tileEntityTypeIn)
{
super(tileEntityTypeIn);
}
// Updates the gear's angle when it's spinning so it spins nice.
@Override
public void tick()
{
if (powers.length >= 6 && angles.length >= 6)
for (int i = 0; i < 6; i++)
{
if (powers[i] > 0 || powers[i] < 0)
this.addAngle(i, powers[i]);
if (powers[i] != 0 && distances[i] > 0)
this.addAngle(i, (powers[i] / 2) + (powers[i] > 0 ? 1 : -1));
}
}
// Tell this GearTileEntity to spin, and then tell the gears around it to do the
// same. Up to 15.
public void spin(World worldIn, BlockPos pos, Direction direction, int distanceIn, int powerIn)
{
if (distanceIn > 0 && this.getPower(direction) == 0 && worldIn.getBlockState(pos).getBlock() == RediscoveredBlocks.gear)
{
if (worldIn.getBlockState(pos).get(GearBlock.EnumFaces.get(direction).face).exists())
{
setDistance(direction, distanceIn);
setPower(direction, powerIn);
// worldIn.getBlockState(pos).updateNeighbors(worldIn, pos, 3);
worldIn.setBlockState(pos, worldIn.getBlockState(pos).with(GearBlock.EnumFaces.get(direction).face, GearBlock.GearStates.POWERED_GEAR), 3);
if (distanceIn <= 1)
return;
for (Direction dir : Direction.values())
{
if (dir.getAxis() != direction.getAxis() && this.getDistance(dir) < distanceIn)
{
// Within same block
spin(worldIn, pos, dir, distanceIn - 1, powerIn * -1);
// Wrap around block
if (worldIn.getTileEntity(pos.offset(direction).offset(dir)) instanceof GearTileEntity)
{
((GearTileEntity) worldIn.getTileEntity(pos.offset(direction).offset(dir))).spin(worldIn, pos.offset(direction).offset(dir), dir.getOpposite(), distanceIn - 1, powerIn * -1);
}
// Adjacent gears
if (worldIn.getTileEntity(pos.offset(dir)) instanceof GearTileEntity)
{
((GearTileEntity) worldIn.getTileEntity(pos.offset(dir))).spin(worldIn, pos.offset(dir), direction, distanceIn - 1, powerIn * -1);
}
}
}
}
}
}
// Tell this gear to stop spinning, and then tell the gears around it to stop as
// well. Same as start code, but setting values to 0 and useing stop instead of
// start.
public void stop(World worldIn, BlockPos pos, Direction direction, int distanceIn)
{
// System.out.println(worldIn.getBlockState(pos).getBlock());
if (distanceIn > 0 && this.getPower(direction) != 0 && worldIn.getBlockState(pos).getBlock() == RediscoveredBlocks.gear)
{
if (worldIn.getBlockState(pos).get(GearBlock.EnumFaces.get(direction).face).exists())
{
setDistance(direction, 0);
setPower(direction, 0);
worldIn.setBlockState(pos, worldIn.getBlockState(pos).with(GearBlock.EnumFaces.get(direction).face, GearBlock.GearStates.GEAR), 3);
if (distanceIn <= 1)
return;
for (Direction dir : Direction.values())
{
if (dir.getAxis() != direction.getAxis() && this.getDistance(dir) < distanceIn)
{
// Within same block
stop(worldIn, pos, dir, distanceIn - 1);
// Wrap around block
if (worldIn.getTileEntity(pos.offset(direction).offset(dir)) instanceof GearTileEntity)
{
((GearTileEntity) worldIn.getTileEntity(pos.offset(direction).offset(dir))).stop(worldIn, pos.offset(direction).offset(dir), dir.getOpposite(), distanceIn - 1);
}
// Adjacent gears
if (worldIn.getTileEntity(pos.offset(dir)) instanceof GearTileEntity)
{
((GearTileEntity) worldIn.getTileEntity(pos.offset(dir))).stop(worldIn, pos.offset(dir), direction, distanceIn - 1);
}
}
}
}
}
}
@Override
public void read(CompoundNBT compound)
{
super.read(compound);
this.powers = compound.getIntArray("Powers");
this.angles = compound.getIntArray("Angles");
this.distances = compound.getIntArray("Distances");
}
@Override
......@@ -49,21 +144,22 @@ public class GearTileEntity extends TileEntity implements ITickableTileEntity
super.write(compound);
compound.putIntArray("Powers", powers);
compound.putIntArray("Angles", angles);
compound.putIntArray("Distances", distances);
return compound;
}
@Override
public CompoundNBT getUpdateTag()
{
return write(new CompoundNBT());
}
@Override
public void handleUpdateTag(CompoundNBT tag)
{
getTileEntity().read(tag);
}
{
getTileEntity().read(tag);
}
@Override
public final SUpdateTileEntityPacket getUpdatePacket()
{
......@@ -75,43 +171,50 @@ public class GearTileEntity extends TileEntity implements ITickableTileEntity
{
read(packet.getNbtCompound());
}
public int[] getPowers()
{
return this.powers;
}
// Gets the power of the face specified.
public int getPower(Direction direction)
{
return this.powers[direction.getIndex()];
}
// Sets the power of the face specified, keeping it between -15 and 15.
public void setPower(Direction direction, int power)
{
if (power < -15 || power > 15)
throw new IllegalArgumentException(String.format("%d is an invalid value. Must be between -15 and 15.", power));
if (power < -15)
power = -15;
if (power > 15)
power = 15;
this.powers[direction.getIndex()] = power;
}
public int[] getAngles()
{
return this.angles;
}
// Gets the angle of the face specified.
public int getAngle(Direction direction)
{
return this.angles[direction.getIndex()];
}
// Gets the angle of the face specified.
public void setAngle(Direction direction, int angle)
{
if (angle < -15 || angle > 15)
throw new IllegalArgumentException(String.format("%d is an invalid value. Must be between 0 and 360.", angle));
if (angle < 0)
angle = 0;
if (angle > 359)
angle = 359;
this.angles[direction.getIndex()] = angle;
}
// Adds to the angle specified, making sure it's within 0 and 359 inclusive.
public void addAngle(int direction, int amount)
{
this.angles[direction] += (amount % 360);
......@@ -120,9 +223,30 @@ public class GearTileEntity extends TileEntity implements ITickableTileEntity
if (this.angles[direction] < 0)
this.angles[direction] += 360;
}
public void addAngle(Direction direction, int amount)
{
this.addAngle(direction.getIndex(), amount);
}
public int[] getDistances()
{
return this.distances;
}
// Gets the distance of the specified side
public int getDistance(Direction direction)
{
return this.distances[direction.getIndex()];
}
// Sets the distance of the specified side, keeping it between 0 and 15
public void setDistance(Direction direction, int distance)
{
if (distance > 15)
distance = 15;
else if (distance < 0)
distance = 0;
this.distances[direction.getIndex()] = distance;
}
}
......@@ -6,7 +6,7 @@
"mode=gear_to_redstone,facing=south,powered=false": { "model": "rediscovered:block/rotational_converter_gr", "y": 180 },
"mode=gear_to_redstone,facing=west,powered=false": { "model": "rediscovered:block/rotational_converter_gr", "y": 270 },
"mode=gear_to_redstone,facing=east,powered=false": { "model": "rediscovered:block/rotational_converter_gr", "y": 90 },
"mode=gear_to_redstone,facing=up,powered=true": { "model": "rediscovered:block/rotational_converter_on_gr", "x": 270 },
"mode=gear_to_redstone,facing=up,powered=true": { "model": "rediscovered:block/rotational_converter_gr_on", "x": 270 },
"mode=gear_to_redstone,facing=down,powered=true": { "model": "rediscovered:block/rotational_converter_gr_on", "x": 90 },
"mode=gear_to_redstone,facing=north,powered=true": { "model": "rediscovered:block/rotational_converter_gr_on" },
"mode=gear_to_redstone,facing=south,powered=true": { "model": "rediscovered:block/rotational_converter_gr_on", "y": 180 },
......
......@@ -12,10 +12,13 @@
],
"conditions": [
{
"condition": "minecraft:block_state_property",
"block": "rediscovered:gear",
"properties": {
"north": "true"
"condition": "minecraft:inverted",
"term": {
"condition": "minecraft:block_state_property",
"block": "rediscovered:gear",
"properties": {
"north_gear": "none"
}
}
},
{
......@@ -34,10 +37,13 @@
],
"conditions": [
{
"condition": "minecraft:block_state_property",
"block": "rediscovered:gear",
"properties": {
"south": "true"
"condition": "minecraft:inverted",
"term": {
"condition": "minecraft:block_state_property",
"block": "rediscovered:gear",
"properties": {
"south_gear": "none"
}
}
},
{
......@@ -56,10 +62,13 @@
],
"conditions": [
{
"condition": "minecraft:block_state_property",
"block": "rediscovered:gear",
"properties": {
"east": "true"
"condition": "minecraft:inverted",
"term": {
"condition": "minecraft:block_state_property",
"block": "rediscovered:gear",
"properties": {
"east_gear": "none"
}
}
},
{
......@@ -78,10 +87,13 @@
],
"conditions": [
{
"condition": "minecraft:block_state_property",
"block": "rediscovered:gear",
"properties": {
"west": "true"
"condition": "minecraft:inverted",
"term": {
"condition": "minecraft:block_state_property",
"block": "rediscovered:gear",
"properties": {
"west_gear": "none"
}
}
},
{
......@@ -100,10 +112,13 @@
],
"conditions": [
{
"condition": "minecraft:block_state_property",
"block": "rediscovered:gear",
"properties": {
"up": "true"
"condition": "minecraft:inverted",
"term": {
"condition": "minecraft:block_state_property",
"block": "rediscovered:gear",
"properties": {
"up_gear": "none"
}
}
},
{
......@@ -122,10 +137,13 @@
],
"conditions": [
{
"condition": "minecraft:block_state_property",
"block": "rediscovered:gear",
"properties": {
"down": "true"
"condition": "minecraft:inverted",
"term": {
"condition": "minecraft:block_state_property",
"block": "rediscovered:gear",
"properties": {
"down_gear": "none"
}
}
},
{
......