From 3ec8afd0912646b8d1fc09097d006ef4ce007220 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Thu, 8 Aug 2019 16:19:16 +0200 Subject: [PATCH] Rudimentary Belts - Second attempt at a practical mechanical belt --- .../java/com/simibubi/create/AllBlocks.java | 3 + .../java/com/simibubi/create/AllItems.java | 11 +- .../com/simibubi/create/AllTileEntities.java | 4 + .../kinetics/base/KineticTileEntity.java | 5 + .../kinetics/relays/AxisTileEntity.java | 5 - .../modules/kinetics/relays/BeltItem.java | 116 +++++++++ .../kinetics/relays/BeltPulleyBlock.java | 32 +++ .../kinetics/relays/BeltPulleyTileEntity.java | 51 ++++ .../relays/BeltPulleyTileEntityRenderer.java | 235 ++++++++++++++++++ .../assets/create/blockstates/belt.json | 9 + .../create/blockstates/belt_pulley.json | 11 + .../resources/assets/create/lang/en_us.json | 2 + .../assets/create/models/block/belt.json | 22 ++ .../assets/create/models/item/belt.json | 6 + .../assets/create/textures/block/belt.png | Bin 0 -> 197 bytes .../create/textures/block/belt_moving.png | Bin 0 -> 250 bytes .../textures/block/belt_moving.png.mcmeta | 7 + .../textures/block/belt_moving_reversed.png | Bin 0 -> 250 bytes .../block/belt_moving_reversed.png.mcmeta | 6 + .../assets/create/textures/item/belt.png | Bin 0 -> 258 bytes 20 files changed, 519 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/simibubi/create/modules/kinetics/relays/BeltItem.java create mode 100644 src/main/java/com/simibubi/create/modules/kinetics/relays/BeltPulleyBlock.java create mode 100644 src/main/java/com/simibubi/create/modules/kinetics/relays/BeltPulleyTileEntity.java create mode 100644 src/main/java/com/simibubi/create/modules/kinetics/relays/BeltPulleyTileEntityRenderer.java create mode 100644 src/main/resources/assets/create/blockstates/belt.json create mode 100644 src/main/resources/assets/create/blockstates/belt_pulley.json create mode 100644 src/main/resources/assets/create/models/block/belt.json create mode 100644 src/main/resources/assets/create/models/item/belt.json create mode 100644 src/main/resources/assets/create/textures/block/belt.png create mode 100644 src/main/resources/assets/create/textures/block/belt_moving.png create mode 100644 src/main/resources/assets/create/textures/block/belt_moving.png.mcmeta create mode 100644 src/main/resources/assets/create/textures/block/belt_moving_reversed.png create mode 100644 src/main/resources/assets/create/textures/block/belt_moving_reversed.png.mcmeta create mode 100644 src/main/resources/assets/create/textures/item/belt.png diff --git a/src/main/java/com/simibubi/create/AllBlocks.java b/src/main/java/com/simibubi/create/AllBlocks.java index 81d468187..8f1dae6d2 100644 --- a/src/main/java/com/simibubi/create/AllBlocks.java +++ b/src/main/java/com/simibubi/create/AllBlocks.java @@ -7,6 +7,7 @@ import com.simibubi.create.modules.kinetics.generators.MotorBlock; import com.simibubi.create.modules.kinetics.receivers.TurntableBlock; import com.simibubi.create.modules.kinetics.relays.AxisBlock; import com.simibubi.create.modules.kinetics.relays.AxisTunnelBlock; +import com.simibubi.create.modules.kinetics.relays.BeltPulleyBlock; import com.simibubi.create.modules.kinetics.relays.CogWheelBlock; import com.simibubi.create.modules.kinetics.relays.GearboxBlock; import com.simibubi.create.modules.kinetics.relays.GearshifterBlock; @@ -40,6 +41,8 @@ public enum AllBlocks { LARGE_GEAR(new CogWheelBlock(true)), AXIS_TUNNEL(new AxisTunnelBlock()), GEARSHIFTER(new GearshifterBlock()), + BELT_PULLEY(new BeltPulleyBlock()), + BELT(new RenderUtilityBlock()), TURNTABLE(new TurntableBlock()), HALF_AXIS(new HalfAxisBlock()), diff --git a/src/main/java/com/simibubi/create/AllItems.java b/src/main/java/com/simibubi/create/AllItems.java index 5cfc0cbc5..e2fceec77 100644 --- a/src/main/java/com/simibubi/create/AllItems.java +++ b/src/main/java/com/simibubi/create/AllItems.java @@ -4,6 +4,8 @@ import com.simibubi.create.modules.curiosities.item.TreeFertilizerItem; import com.simibubi.create.modules.curiosities.placementHandgun.BuilderGunItem; import com.simibubi.create.modules.curiosities.placementHandgun.BuilderGunItemRenderer; import com.simibubi.create.modules.curiosities.placementHandgun.BuilderGunModel; +import com.simibubi.create.modules.kinetics.relays.BeltItem; +import com.simibubi.create.modules.kinetics.relays.BeltPulleyTileEntityRenderer; import com.simibubi.create.modules.schematics.item.BlueprintAndQuillItem; import com.simibubi.create.modules.schematics.item.BlueprintItem; import com.simibubi.create.modules.symmetry.SymmetryWandItem; @@ -12,11 +14,13 @@ import com.simibubi.create.modules.symmetry.client.SymmetryWandModel; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.ModelResourceLocation; +import net.minecraft.client.renderer.model.ModelRotation; import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer; import net.minecraft.item.Item; import net.minecraft.item.Item.Properties; import net.minecraft.item.ItemStack; import net.minecraft.item.Rarity; +import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.event.ModelBakeEvent; @@ -40,7 +44,9 @@ public enum AllItems { EMPTY_BLUEPRINT(new Item(standardProperties().maxStackSize(1))), BLUEPRINT_AND_QUILL(new BlueprintAndQuillItem(standardProperties().maxStackSize(1))), BLUEPRINT(new BlueprintItem(standardProperties())), - + + BELT(new BeltItem(standardProperties())), + ; public Item item; @@ -88,6 +94,9 @@ public enum AllItems { ModelResourceLocation handgunLocation = getModelLocation(PLACEMENT_HANDGUN); template = event.getModelRegistry().get(handgunLocation); event.getModelRegistry().put(handgunLocation, new BuilderGunModel(template).loadPartials(event)); + + BeltPulleyTileEntityRenderer.beltModel = event.getModelLoader() + .func_217845_a(new ResourceLocation(Create.ID, "block/belt"), ModelRotation.X0_Y0); } protected static ModelResourceLocation getModelLocation(AllItems item) { diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index 94f4c4bdb..1146a63eb 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -9,6 +9,8 @@ import com.simibubi.create.modules.kinetics.receivers.TurntableTileEntity; import com.simibubi.create.modules.kinetics.relays.AxisTileEntity; import com.simibubi.create.modules.kinetics.relays.AxisTunnelTileEntity; import com.simibubi.create.modules.kinetics.relays.AxisTunnelTileEntityRenderer; +import com.simibubi.create.modules.kinetics.relays.BeltPulleyTileEntity; +import com.simibubi.create.modules.kinetics.relays.BeltPulleyTileEntityRenderer; import com.simibubi.create.modules.kinetics.relays.GearboxTileEntity; import com.simibubi.create.modules.kinetics.relays.GearboxTileEntityRenderer; import com.simibubi.create.modules.kinetics.relays.GearshifterTileEntity; @@ -44,6 +46,7 @@ public enum AllTileEntities { TURNTABLE(TurntableTileEntity::new, AllBlocks.TURNTABLE), AXIS_TUNNEL(AxisTunnelTileEntity::new, AllBlocks.AXIS_TUNNEL), GEARSHIFTER(GearshifterTileEntity::new, AllBlocks.GEARSHIFTER), + BELT_PULLEY(BeltPulleyTileEntity::new, AllBlocks.BELT_PULLEY), ; @@ -80,6 +83,7 @@ public enum AllTileEntities { bind(AxisTunnelTileEntity.class, new AxisTunnelTileEntityRenderer()); bind(GearboxTileEntity.class, new GearboxTileEntityRenderer()); bind(GearshifterTileEntity.class, new GearshifterTileEntityRenderer()); + bind(BeltPulleyTileEntity.class, new BeltPulleyTileEntityRenderer()); } @OnlyIn(Dist.CLIENT) diff --git a/src/main/java/com/simibubi/create/modules/kinetics/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/modules/kinetics/base/KineticTileEntity.java index 41eff530c..20c45a992 100644 --- a/src/main/java/com/simibubi/create/modules/kinetics/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/kinetics/base/KineticTileEntity.java @@ -26,6 +26,11 @@ public abstract class KineticTileEntity extends SyncedTileEntity { source = Optional.empty(); } + @Override + public boolean hasFastRenderer() { + return true; + } + @Override public void onLoad() { if (!hasWorld()) diff --git a/src/main/java/com/simibubi/create/modules/kinetics/relays/AxisTileEntity.java b/src/main/java/com/simibubi/create/modules/kinetics/relays/AxisTileEntity.java index a755e091e..bc29ec114 100644 --- a/src/main/java/com/simibubi/create/modules/kinetics/relays/AxisTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/kinetics/relays/AxisTileEntity.java @@ -9,9 +9,4 @@ public class AxisTileEntity extends KineticTileEntity { super(AllTileEntities.AXIS.type); } - @Override - public boolean hasFastRenderer() { - return true; - } - } diff --git a/src/main/java/com/simibubi/create/modules/kinetics/relays/BeltItem.java b/src/main/java/com/simibubi/create/modules/kinetics/relays/BeltItem.java new file mode 100644 index 000000000..cd365edda --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/kinetics/relays/BeltItem.java @@ -0,0 +1,116 @@ +package com.simibubi.create.modules.kinetics.relays; + +import com.simibubi.create.AllBlocks; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemUseContext; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.NBTUtil; +import net.minecraft.state.properties.BlockStateProperties; +import net.minecraft.util.ActionResultType; +import net.minecraft.util.Direction.Axis; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class BeltItem extends Item { + + public static final int MAX_PULLEY_DISTANCE = 20; + + public BeltItem(Properties properties) { + super(properties); + } + + @Override + public ActionResultType onItemUse(ItemUseContext context) { + World world = context.getWorld(); + BlockPos pos = context.getPos(); + boolean validAxis = validateAxis(world, pos); + + if (world.isRemote) + return validAxis ? ActionResultType.SUCCESS : ActionResultType.FAIL; + + CompoundNBT tag = context.getItem().getOrCreateTag(); + BlockPos firstPulley = null; + + // Remove first if no longer existant or valid + if (tag.contains("FirstPulley")) { + firstPulley = NBTUtil.readBlockPos(tag.getCompound("FirstPulley")); + if (!validateAxis(world, firstPulley)) { + tag.remove("FirstPulley"); + context.getItem().setTag(tag); + } + } + + if (!validAxis) + return ActionResultType.FAIL; + + if (tag.contains("FirstPulley")) { + + if (!canConnect(world, firstPulley, pos)) + return ActionResultType.FAIL; + + if (!firstPulley.equals(pos)) { + makePulley(world, firstPulley); + makePulley(world, pos); + connectPulley(world, firstPulley, pos, true); + connectPulley(world, pos, firstPulley, false); + + if (!context.getPlayer().isCreative()) + context.getItem().shrink(1); + } + + tag.remove("FirstPulley"); + if (!context.getItem().isEmpty()) { + context.getItem().setTag(tag); + context.getPlayer().getCooldownTracker().setCooldown(this, 5); + } + return ActionResultType.SUCCESS; + } + + tag.put("FirstPulley", NBTUtil.writeBlockPos(pos)); + context.getItem().setTag(tag); + context.getPlayer().getCooldownTracker().setCooldown(this, 5); + return ActionResultType.SUCCESS; + } + + private void makePulley(World world, BlockPos pos) { + world.setBlockState(pos, AllBlocks.BELT_PULLEY.get().getDefaultState().with(BlockStateProperties.AXIS, + world.getBlockState(pos).get(BlockStateProperties.AXIS))); + } + + private void connectPulley(World world, BlockPos pos, BlockPos target, boolean controller) { + BeltPulleyTileEntity te = (BeltPulleyTileEntity) world.getTileEntity(pos); + if (te != null) { + te.setController(controller); + te.setTarget(target); + } + } + + private boolean canConnect(World world, BlockPos first, BlockPos second) { + if (!world.isAreaLoaded(first, 1)) + return false; + if (!world.isAreaLoaded(second, 1)) + return false; + if (!second.withinDistance(first, MAX_PULLEY_DISTANCE)) + return false; + + BlockPos diff = second.subtract(first); + Axis axis = world.getBlockState(first).get(BlockStateProperties.AXIS); + + if (axis.getCoordinate(diff.getX(), diff.getY(), diff.getZ()) != 0) + return false; + if (axis != world.getBlockState(second).get(BlockStateProperties.AXIS)) + return false; + + return true; + } + + private boolean validateAxis(World world, BlockPos pos) { + if (!world.isAreaLoaded(pos, 1)) + return false; + if (!AllBlocks.AXIS.typeOf(world.getBlockState(pos))) + return false; + return true; + } + +} diff --git a/src/main/java/com/simibubi/create/modules/kinetics/relays/BeltPulleyBlock.java b/src/main/java/com/simibubi/create/modules/kinetics/relays/BeltPulleyBlock.java new file mode 100644 index 000000000..4bdf53ac6 --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/kinetics/relays/BeltPulleyBlock.java @@ -0,0 +1,32 @@ +package com.simibubi.create.modules.kinetics.relays; + +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.shapes.ISelectionContext; +import net.minecraft.util.math.shapes.VoxelShape; +import net.minecraft.world.IBlockReader; + +public class BeltPulleyBlock extends AxisBlock { + + public BeltPulleyBlock() { + super(Properties.from(Blocks.ANDESITE)); + } + + @Override + public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { + return makeCuboidShape(-16, -16, -16, 32, 32, 32); + } + + @Override + public TileEntity createTileEntity(BlockState state, IBlockReader world) { + return new BeltPulleyTileEntity(); + } + + @Override + protected boolean hasStaticPart() { + return false; // static addons like chutes + } + +} diff --git a/src/main/java/com/simibubi/create/modules/kinetics/relays/BeltPulleyTileEntity.java b/src/main/java/com/simibubi/create/modules/kinetics/relays/BeltPulleyTileEntity.java new file mode 100644 index 000000000..a0d6cdbcc --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/kinetics/relays/BeltPulleyTileEntity.java @@ -0,0 +1,51 @@ +package com.simibubi.create.modules.kinetics.relays; + +import com.simibubi.create.AllTileEntities; +import com.simibubi.create.modules.kinetics.base.KineticTileEntity; + +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.NBTUtil; +import net.minecraft.util.math.BlockPos; + +public class BeltPulleyTileEntity extends KineticTileEntity { + + protected boolean controller; + protected BlockPos target; + + public BeltPulleyTileEntity() { + super(AllTileEntities.BELT_PULLEY.type); + controller = false; + target = BlockPos.ZERO; + } + + @Override + public CompoundNBT write(CompoundNBT compound) { + compound.putBoolean("Controller", isController()); + compound.put("Target", NBTUtil.writeBlockPos(target)); + return super.write(compound); + } + + @Override + public void read(CompoundNBT compound) { + controller = compound.getBoolean("Controller"); + target = NBTUtil.readBlockPos(compound.getCompound("Target")); + super.read(compound); + } + + public void setController(boolean controller) { + this.controller = controller; + } + + public boolean isController() { + return controller; + } + + public void setTarget(BlockPos target) { + this.target = target; + } + + public BlockPos getTarget() { + return target; + } + +} diff --git a/src/main/java/com/simibubi/create/modules/kinetics/relays/BeltPulleyTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/kinetics/relays/BeltPulleyTileEntityRenderer.java new file mode 100644 index 000000000..a5b82e229 --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/kinetics/relays/BeltPulleyTileEntityRenderer.java @@ -0,0 +1,235 @@ +package com.simibubi.create.modules.kinetics.relays; + +import java.nio.ByteBuffer; +import java.util.Random; +import java.util.concurrent.TimeUnit; + +import org.lwjgl.opengl.GL11; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import com.simibubi.create.AllBlocks; +import com.simibubi.create.modules.kinetics.base.KineticTileEntity; +import com.simibubi.create.modules.kinetics.base.KineticTileEntityRenderer; + +import net.minecraft.block.BlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.BlockModelRenderer; +import net.minecraft.client.renderer.BlockRendererDispatcher; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.GLAllocation; +import net.minecraft.client.renderer.model.IBakedModel; +import net.minecraft.client.renderer.texture.AtlasTexture; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.state.properties.BlockStateProperties; +import net.minecraft.util.Direction; +import net.minecraft.util.Direction.Axis; +import net.minecraft.util.Direction.AxisDirection; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; +import net.minecraftforge.client.model.animation.Animation; +import net.minecraftforge.client.model.data.EmptyModelData; + +public class BeltPulleyTileEntityRenderer extends KineticTileEntityRenderer { + + protected static Cache cachedBelts; + public static IBakedModel beltModel; + + protected class CachedBeltBuffer { + ByteBuffer original; + ByteBuffer mutable; + + public CachedBeltBuffer(ByteBuffer original, float beltLength, float angle, Axis axis) { + original.rewind(); + this.original = original; + this.mutable = GLAllocation.createDirectByteBuffer(original.capacity()); + this.mutable.order(original.order()); + + int limitBefore = this.original.limit(); + int integerSize = DefaultVertexFormats.BLOCK.getIntegerSize(); + int amtBytesCopied = 0; // 2/*Blocks*/ * 6/*Quads*/ * 4/*Vertices*/ * integerSize; + + this.original.limit(limitBefore + amtBytesCopied); + this.mutable.limit(limitBefore + amtBytesCopied); + +// for (int i = 0; i < amtBytesCopied; i++) +// this.original.put(i + limitBefore, this.original.get(i)); +// int vertex = limitBefore / integerSize; +// putPos(this.original, vertex, getPos(this.original, vertex).add(0,1,0)); + + mutable.put(this.original); + this.original.rewind(); + mutable.rewind(); + } + + private Vec3d getPos(ByteBuffer buffer, int vertex) { + return new Vec3d(buffer.getFloat(vertex), buffer.getFloat(vertex + 4), buffer.getFloat(vertex + 8)); + } + + private void putPos(ByteBuffer buffer, int vertex, Vec3d pos) { + buffer.putFloat(vertex, (float) pos.x); + buffer.putFloat(vertex + 4, (float) pos.y); + buffer.putFloat(vertex + 8, (float) pos.z); + } + + private Vec3d rotatePos(Vec3d pos, float angle, Axis axis) { + return rotatePos(pos, MathHelper.sin(angle), MathHelper.cos(angle), axis); + } + + private Vec3d rotatePos(Vec3d pos, float sin, float cos, Axis axis) { + final float x = (float) pos.x; + final float y = (float) pos.y; + final float z = (float) pos.z; + + if (axis == Axis.X) + return new Vec3d(x, y * cos - z * sin, z * cos + y * sin); + if (axis == Axis.Y) + return new Vec3d(x * cos + z * sin, y, z * cos - x * sin); + if (axis == Axis.Z) + return new Vec3d(x * cos - y * sin, y * cos + x * sin, z); + + return pos; + } + + public ByteBuffer getTransformed(Vec3d translation, BeltPulleyTileEntity te, boolean flipped) { + original.rewind(); + mutable.rewind(); + + final Axis axis = te.getBlockState().get(BlockStateProperties.AXIS); + final BlockPos diff = te.getTarget().subtract(te.getPos()); + float angle = 0; + + if (axis == Axis.X) + angle = (float) MathHelper.atan2(-diff.getY(), diff.getZ()); + if (axis == Axis.Y) + angle = (float) MathHelper.atan2(diff.getX(), diff.getZ()); + if (axis == Axis.Z) + angle = (float) MathHelper.atan2(diff.getY(), diff.getX()); + + final float time = Animation.getWorldTime(Minecraft.getInstance().world, + Minecraft.getInstance().getRenderPartialTicks()); + final float progress = ((te.getSpeed() * time / 16) % 16) / 16f; + float beltLength = (float) new Vec3d(te.getPos()).distanceTo(new Vec3d(te.getTarget())) + .5f; + + final BlockState blockState = te.getBlockState(); + final int packedLightCoords = blockState.getPackedLightmapCoords(getWorld(), te.getPos()); + final int formatLength = DefaultVertexFormats.BLOCK.getSize(); + final Vec3d half = new Vec3d(.5f, .5f, .5f); + final float cos = MathHelper.cos(angle); + final float sin = MathHelper.sin(angle); + final Vec3d offset = new Vec3d(0, .25f, -.25f + progress + (te.getSpeed() < 0 ? 0 : -1)); + Vec3d trans = new Vec3d(Direction.getFacingFromAxis(AxisDirection.NEGATIVE, axis).getDirectionVec()) + .scale(.5f); + TextureAtlasSprite sprite = Minecraft.getInstance().getTextureMap() + .getSprite(AtlasTexture.LOCATION_BLOCKS_TEXTURE); + final int texHeight = sprite.getHeight(); + + for (int i = 0; i < original.limit() / formatLength; i++) { + final int position = i * formatLength; + + // Cut-off + mutable.putFloat(position + 20, original.getFloat(position + 20)); + + Vec3d localPos = getPos(this.original, position).add(offset); + if (localPos.z < -.25f) { + mutable.putFloat(position + 20, (float) (original.getFloat(position + 20) + - (Math.min(localPos.z + .25f, 0)) * .5f / texHeight)); + localPos = new Vec3d(localPos.x, localPos.y, -.25f); + } + if (localPos.z > beltLength - .25f) { + mutable.putFloat(position + 20, (float) (original.getFloat(position + 20) + - (Math.min(localPos.z - beltLength + .25f, 1f)) * .5f / texHeight)); + localPos = new Vec3d(localPos.x, localPos.y, beltLength - .25f); + } + + // Transform Vertex + Vec3d pos = localPos; + + if (axis == Axis.Z) + pos = rotatePos(pos.subtract(half), (float) (Math.PI / 2f), Axis.Y).add(half); + if (axis == Axis.Y) + pos = rotatePos(pos, (float) (Math.PI / 2f), Axis.Z); + + pos = rotatePos(pos, sin, cos, axis).add(trans).add(half); + + // Flip + if (flipped) { + pos = rotatePos(pos.subtract(half), (float) Math.PI, axis); + pos = pos.add(half).add(new Vec3d(diff)); + } + + putPos(mutable, position, pos.add(translation)); + mutable.putInt(position + 24, packedLightCoords); + } + return mutable; + } + } + + public BeltPulleyTileEntityRenderer() { + super(); + cachedBelts = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.SECONDS).build(); + } + + @Override + public void renderTileEntityFast(KineticTileEntity te, double x, double y, double z, float partialTicks, + int destroyStage, BufferBuilder buffer) { + super.renderTileEntityFast(te, x, y, z, partialTicks, destroyStage, buffer); + + BeltPulleyTileEntity beltPulleyTE = (BeltPulleyTileEntity) te; + if (!beltPulleyTE.isController()) + return; + + cacheBeltIfMissing(beltPulleyTE); + renderBeltFromCache(te, new Vec3d(x, y, z), buffer); + } + + @Override + protected BlockState getRenderedBlockState(KineticTileEntity te) { + return AllBlocks.AXIS.get().getDefaultState().with(BlockStateProperties.AXIS, + te.getBlockState().get(BlockStateProperties.AXIS)); + } + + protected void cacheBeltIfMissing(BeltPulleyTileEntity te) { + if (cachedBelts.getIfPresent(te) != null) + return; + + BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher(); + BlockModelRenderer blockRenderer = dispatcher.getBlockModelRenderer(); + BufferBuilder builder = new BufferBuilder(0); + Random random = new Random(); + + builder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); + + float beltLength = (float) new Vec3d(te.getPos()).distanceTo(new Vec3d(te.getTarget())) + .5f; + int length = MathHelper.ceil(beltLength) + 1; + for (int segment = 0; segment < length; segment++) { + builder.setTranslation(0, 0, segment); + blockRenderer.renderModelFlat(getWorld(), beltModel, te.getBlockState(), BlockPos.ZERO, builder, true, + random, 42, EmptyModelData.INSTANCE); + } + builder.finishDrawing(); + + Axis axis = te.getBlockState().get(BlockStateProperties.AXIS); + BlockPos diff = te.getTarget().subtract(te.getPos()); + float angle = 0; + + if (axis == Axis.X) + angle = (float) MathHelper.atan2(-diff.getY(), diff.getZ()); + if (axis == Axis.Y) + angle = (float) MathHelper.atan2(diff.getX(), diff.getZ()); + if (axis == Axis.Z) + angle = (float) MathHelper.atan2(diff.getY(), diff.getX()); + + cachedBelts.put(te, new CachedBeltBuffer(builder.getByteBuffer(), beltLength, angle, axis)); + + } + + public void renderBeltFromCache(KineticTileEntity te, Vec3d translation, BufferBuilder buffer) { + if (buffer == null) + return; + buffer.putBulkData(cachedBelts.getIfPresent(te).getTransformed(translation, (BeltPulleyTileEntity) te, false)); + buffer.putBulkData(cachedBelts.getIfPresent(te).getTransformed(translation, (BeltPulleyTileEntity) te, true)); + } +} diff --git a/src/main/resources/assets/create/blockstates/belt.json b/src/main/resources/assets/create/blockstates/belt.json new file mode 100644 index 000000000..7584621cc --- /dev/null +++ b/src/main/resources/assets/create/blockstates/belt.json @@ -0,0 +1,9 @@ +{ + "forgemarker": 1, + "defaults": { + "model": "create:block/belt" + }, + "variants": { + "": { "model": "create:block/belt" } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/create/blockstates/belt_pulley.json b/src/main/resources/assets/create/blockstates/belt_pulley.json new file mode 100644 index 000000000..8078a810d --- /dev/null +++ b/src/main/resources/assets/create/blockstates/belt_pulley.json @@ -0,0 +1,11 @@ +{ + "forgemarker": 1, + "defaults": { + "model": "block/dirt" + }, + "variants": { + "axis=y": { "model": "block/dirt" }, + "axis=z": { "model": "block/dirt", "x": 90 }, + "axis=x": { "model": "block/dirt", "x": 90, "y": 90 } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/create/lang/en_us.json b/src/main/resources/assets/create/lang/en_us.json index 1e2f58837..93a31a744 100644 --- a/src/main/resources/assets/create/lang/en_us.json +++ b/src/main/resources/assets/create/lang/en_us.json @@ -8,6 +8,7 @@ "item.create.chorus_chrome_cube": "Chorus Chrome", "item.create.blueprint_and_quill": "Schematic and Quill", "item.create.blueprint": "Schematic", + "item.create.belt": "Mechanical Belt", "block.create.gear": "Cogwheel", "block.create.large_gear": "Large Cogwheel", "block.create.turntable": "Turntable", @@ -16,6 +17,7 @@ "block.create.axis_tunnel": "Encased Axis", "block.create.axis": "Axis", "block.create.motor": "Motor", + "block.create.belt_pulley": "Belt Pulley", "block.create.schematicannon": "Schematicannon", "block.create.schematic_table": "Schematic Table", "block.create.creative_crate": "Schematicannon Creatifier", diff --git a/src/main/resources/assets/create/models/block/belt.json b/src/main/resources/assets/create/models/block/belt.json new file mode 100644 index 000000000..d1358f457 --- /dev/null +++ b/src/main/resources/assets/create/models/block/belt.json @@ -0,0 +1,22 @@ +{ + "__comment": "Model generated using MrCrayfish's Model Creator (http://mrcrayfish.com/modelcreator/)", + "parent": "block/cube", + "textures": { + "0": "create:block/belt" + }, + "elements": [ + { + "name": "Belt", + "from": [ 1.0, 0.0, 0.0 ], + "to": [ 15.0, 2.0, 16.0 ], + "faces": { + "north": { "texture": "#0", "uv": [ 1.0, 0.0, 15.0, 2.0 ], "rotation": 180 }, + "east": { "texture": "#0", "uv": [ 14.0, 0.0, 16.0, 16.0 ], "rotation": 90 }, + "south": { "texture": "#0", "uv": [ 1.0, 14.0, 15.0, 16.0 ]}, + "west": { "texture": "#0", "uv": [ 0.0, 0.0, 2.0, 16.0 ], "rotation": 270 }, + "up": { "texture": "#0", "uv": [ 1.0, 0.0, 15.0, 16.0 ] }, + "down": { "texture": "#0", "uv": [ 1.0, 0.0, 15.0, 16.0 ], "rotation": 180 } + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/create/models/item/belt.json b/src/main/resources/assets/create/models/item/belt.json new file mode 100644 index 000000000..b94222daf --- /dev/null +++ b/src/main/resources/assets/create/models/item/belt.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "create:item/belt" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/create/textures/block/belt.png b/src/main/resources/assets/create/textures/block/belt.png new file mode 100644 index 0000000000000000000000000000000000000000..ce2eef5136e58ebdde2f0c1b1cab777089a8d810 GIT binary patch literal 197 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|Ea{HEjtmSN`?>!lvI6;>1s;*b z3=Dh+K$tP>S|=w^P@=>&q9iy!t)x7$D3zfgF*C13FE6!3!9>qc&+M-s=L?`3XHOT$ z5DWk0fJe{F!UH~-7%6o$oNDNj{2?h3!ot!}Q=OapM+`rV7lLFmBzoEyLwO{4 nk6bih5L}#Su;uUrduE1tU$nh`hOE*Cx`Dyd)z4*}Q$iB}ocu~r literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt_moving.png.mcmeta b/src/main/resources/assets/create/textures/block/belt_moving.png.mcmeta new file mode 100644 index 000000000..65a5e3e16 --- /dev/null +++ b/src/main/resources/assets/create/textures/block/belt_moving.png.mcmeta @@ -0,0 +1,7 @@ +{ + "animation": { + "interpolate": false, + "frametime": 1, + "frames": [ 3, 2, 1, 0 ] + } +} diff --git a/src/main/resources/assets/create/textures/block/belt_moving_reversed.png b/src/main/resources/assets/create/textures/block/belt_moving_reversed.png new file mode 100644 index 0000000000000000000000000000000000000000..fb689903fd8bc49d05bf46a94c37b37efe398368 GIT binary patch literal 250 zcmeAS@N?(olHy`uVBq!ia0vp^0zmA*!3HFSYrjteQY`6?zK#qG8~eHcB(eheoCO|{ z#S9F5hd`K7RKu$QC@4|l8c`CQpH@+`rV7lLFmBzoEyLwO{4 nk6bih5L}#Su;uUrduE1tU$nh`hOE*Cx`Dyd)z4*}Q$iB}ocu~r literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt_moving_reversed.png.mcmeta b/src/main/resources/assets/create/textures/block/belt_moving_reversed.png.mcmeta new file mode 100644 index 000000000..a328ca58d --- /dev/null +++ b/src/main/resources/assets/create/textures/block/belt_moving_reversed.png.mcmeta @@ -0,0 +1,6 @@ +{ + "animation": { + "interpolate": false, + "frametime": 1 + } +} diff --git a/src/main/resources/assets/create/textures/item/belt.png b/src/main/resources/assets/create/textures/item/belt.png new file mode 100644 index 0000000000000000000000000000000000000000..772436f7e58dbe0c41f7e493ecfd201428bc6a47 GIT binary patch literal 258 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=DjSK$uZf!>a)(C{f}XQ4*Y=R#Ki=l*&+$n3-3imzP?iV4`QJXZF{R^94{%gQtsQ zh=u>szKy&M20Sb`nIagEu;{&5kSOrt#(u-1kDab@oMJ~cFYW#7w|v$91x8F$1y}Sq zq_Su!2S_%adcEiB=6rX?v~Jglq0cij_k}4b?R-!x`eXGzmi->5#kM$f?sc|*#>AqV zb54IblQ2j2jXCjttZav*W_%S<;+lH@;yXskXOr?KNVjYOx`n~h)z4*}Q$iB}4qR8p literal 0 HcmV?d00001