Family reunion

- Mechanical Bearings now use Contraption Entities for their structures
- Fixed Mounted Contraptions being slightly offset
This commit is contained in:
simibubi 2019-12-07 00:07:49 +01:00
parent 1563a3991c
commit da27a63447
39 changed files with 301 additions and 539 deletions

View file

@ -20,17 +20,17 @@ import com.simibubi.create.modules.contraptions.receivers.HarvesterBlock;
import com.simibubi.create.modules.contraptions.receivers.HarvesterBlock.HarvesterBladeBlock;
import com.simibubi.create.modules.contraptions.receivers.MechanicalMixerBlock;
import com.simibubi.create.modules.contraptions.receivers.MechanicalMixerBlock.MechanicalMixerBlockItem;
import com.simibubi.create.modules.contraptions.receivers.contraptions.bearing.MechanicalBearingBlock;
import com.simibubi.create.modules.contraptions.receivers.contraptions.chassis.LinearChassisBlock;
import com.simibubi.create.modules.contraptions.receivers.contraptions.chassis.RadialChassisBlock;
import com.simibubi.create.modules.contraptions.receivers.contraptions.mounted.CartAssemblerBlock;
import com.simibubi.create.modules.contraptions.receivers.contraptions.mounted.CartAssemblerBlock.MinecartAnchorBlock;
import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.MechanicalPistonBlock;
import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.MechanicalPistonHeadBlock;
import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.PistonPoleBlock;
import com.simibubi.create.modules.contraptions.receivers.MechanicalPressBlock;
import com.simibubi.create.modules.contraptions.receivers.SawBlock;
import com.simibubi.create.modules.contraptions.receivers.TurntableBlock;
import com.simibubi.create.modules.contraptions.receivers.constructs.LinearChassisBlock;
import com.simibubi.create.modules.contraptions.receivers.constructs.RadialChassisBlock;
import com.simibubi.create.modules.contraptions.receivers.constructs.bearing.MechanicalBearingBlock;
import com.simibubi.create.modules.contraptions.receivers.constructs.mounted.CartAssemblerBlock;
import com.simibubi.create.modules.contraptions.receivers.constructs.mounted.CartAssemblerBlock.MinecartAnchorBlock;
import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonBlock;
import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonHeadBlock;
import com.simibubi.create.modules.contraptions.receivers.constructs.piston.PistonPoleBlock;
import com.simibubi.create.modules.contraptions.receivers.crafter.MechanicalCrafterBlock;
import com.simibubi.create.modules.contraptions.redstone.ContactBlock;
import com.simibubi.create.modules.contraptions.relays.ClutchBlock;

View file

@ -2,8 +2,8 @@ package com.simibubi.create;
import java.util.function.Function;
import com.simibubi.create.modules.contraptions.receivers.constructs.mounted.ContraptionEntity;
import com.simibubi.create.modules.contraptions.receivers.constructs.mounted.ContraptionEntityRenderer;
import com.simibubi.create.modules.contraptions.receivers.contraptions.ContraptionEntity;
import com.simibubi.create.modules.contraptions.receivers.contraptions.ContraptionEntityRenderer;
import com.simibubi.create.modules.logistics.transport.CardboardBoxEntity;
import com.simibubi.create.modules.logistics.transport.CardboardBoxEntityRenderer;

View file

@ -8,7 +8,7 @@ import com.simibubi.create.foundation.packet.NbtPacket;
import com.simibubi.create.foundation.packet.SimplePacketBase;
import com.simibubi.create.modules.contraptions.generators.ConfigureMotorPacket;
import com.simibubi.create.modules.contraptions.receivers.ConfigureMixerPacket;
import com.simibubi.create.modules.contraptions.receivers.constructs.ConfigureChassisPacket;
import com.simibubi.create.modules.contraptions.receivers.contraptions.chassis.ConfigureChassisPacket;
import com.simibubi.create.modules.curiosities.placementHandgun.BuilderGunBeamPacket;
import com.simibubi.create.modules.curiosities.symmetry.SymmetryEffectPacket;
import com.simibubi.create.modules.logistics.block.diodes.ConfigureFlexpeaterPacket;

View file

@ -24,11 +24,11 @@ import com.simibubi.create.modules.contraptions.receivers.MechanicalPressTileEnt
import com.simibubi.create.modules.contraptions.receivers.SawTileEntity;
import com.simibubi.create.modules.contraptions.receivers.SawTileEntityRenderer;
import com.simibubi.create.modules.contraptions.receivers.TurntableTileEntity;
import com.simibubi.create.modules.contraptions.receivers.constructs.ChassisTileEntity;
import com.simibubi.create.modules.contraptions.receivers.constructs.bearing.MechanicalBearingTileEntity;
import com.simibubi.create.modules.contraptions.receivers.constructs.bearing.MechanicalBearingTileEntityRenderer;
import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonTileEntity;
import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonTileEntityRenderer;
import com.simibubi.create.modules.contraptions.receivers.contraptions.bearing.MechanicalBearingTileEntity;
import com.simibubi.create.modules.contraptions.receivers.contraptions.bearing.MechanicalBearingTileEntityRenderer;
import com.simibubi.create.modules.contraptions.receivers.contraptions.chassis.ChassisTileEntity;
import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.MechanicalPistonTileEntity;
import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.MechanicalPistonTileEntityRenderer;
import com.simibubi.create.modules.contraptions.receivers.crafter.MechanicalCrafterTileEntity;
import com.simibubi.create.modules.contraptions.receivers.crafter.MechanicalCrafterTileEntityRenderer;
import com.simibubi.create.modules.contraptions.relays.ClutchTileEntity;

View file

@ -14,7 +14,7 @@ import com.simibubi.create.foundation.utility.SuperByteBufferCache;
import com.simibubi.create.modules.contraptions.WrenchModel;
import com.simibubi.create.modules.contraptions.base.KineticTileEntityRenderer;
import com.simibubi.create.modules.contraptions.receivers.EncasedFanParticleHandler;
import com.simibubi.create.modules.contraptions.receivers.constructs.ContraptionRenderer;
import com.simibubi.create.modules.contraptions.receivers.contraptions.ContraptionRenderer;
import com.simibubi.create.modules.curiosities.deforester.DeforesterModel;
import com.simibubi.create.modules.curiosities.partialWindows.WindowInABlockModel;
import com.simibubi.create.modules.curiosities.placementHandgun.BuilderGunModel;

View file

@ -1,7 +1,6 @@
package com.simibubi.create;
import com.simibubi.create.foundation.block.SpriteShifter;
import com.simibubi.create.modules.contraptions.receivers.constructs.bearing.MechanicalBearingTileEntityRenderer;
import net.minecraft.client.resources.ReloadListener;
import net.minecraft.profiler.IProfiler;
@ -16,7 +15,6 @@ public class ResourceReloadHandler extends ReloadListener<String> {
@Override
protected void apply(String splashList, IResourceManager resourceManagerIn, IProfiler profilerIn) {
MechanicalBearingTileEntityRenderer.invalidateCache();
SpriteShifter.reloadUVs();
CreateClient.bufferCache.invalidate();
}

View file

@ -7,7 +7,7 @@ import com.simibubi.create.foundation.block.IWithTileEntity;
import com.simibubi.create.foundation.utility.SuperByteBuffer;
import com.simibubi.create.foundation.utility.VoxelShapers;
import com.simibubi.create.modules.contraptions.base.DirectionalKineticBlock;
import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior;
import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;

View file

@ -9,7 +9,7 @@ import com.simibubi.create.foundation.utility.SuperByteBuffer;
import com.simibubi.create.modules.contraptions.base.IRotate;
import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
import com.simibubi.create.modules.contraptions.base.KineticTileEntityRenderer;
import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior.MovementContext;
import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior.MovementContext;
import net.minecraft.block.BlockState;
import net.minecraft.util.Direction.Axis;

View file

@ -6,7 +6,7 @@ import com.simibubi.create.AllBlocks;
import com.simibubi.create.foundation.block.IRenderUtilityBlock;
import com.simibubi.create.foundation.utility.SuperByteBuffer;
import com.simibubi.create.foundation.utility.VoxelShaper;
import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior;
import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;

View file

@ -7,7 +7,7 @@ import com.simibubi.create.AllBlocks;
import com.simibubi.create.CreateClient;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.foundation.utility.SuperByteBuffer;
import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior.MovementContext;
import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior.MovementContext;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.BufferBuilder;

View file

@ -3,7 +3,7 @@ package com.simibubi.create.modules.contraptions.receivers;
import com.simibubi.create.foundation.block.IWithTileEntity;
import com.simibubi.create.foundation.utility.VoxelShapers;
import com.simibubi.create.modules.contraptions.base.DirectionalAxisKineticBlock;
import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior;
import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior;
import com.simibubi.create.modules.logistics.block.IBlockWithFilter;
import net.minecraft.block.Block;

View file

@ -1,108 +0,0 @@
package com.simibubi.create.modules.contraptions.receivers.constructs.bearing;
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.CreateClient;
import com.simibubi.create.foundation.utility.PlacementSimulationWorld;
import com.simibubi.create.foundation.utility.SuperByteBuffer;
import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
import com.simibubi.create.modules.contraptions.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.model.IBakedModel;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.gen.feature.template.Template.BlockInfo;
import net.minecraftforge.client.model.data.EmptyModelData;
public class MechanicalBearingTileEntityRenderer extends KineticTileEntityRenderer {
protected static Cache<RotationConstruct, RotationConstructVertexBuffer> cachedConstructs;
protected static PlacementSimulationWorld renderWorld;
@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);
MechanicalBearingTileEntity bearingTe = (MechanicalBearingTileEntity) te;
final Direction facing = te.getBlockState().get(BlockStateProperties.FACING);
BlockState capState = AllBlocks.MECHANICAL_BEARING_TOP.get().getDefaultState().with(BlockStateProperties.FACING,
facing);
SuperByteBuffer superBuffer = CreateClient.bufferCache.renderBlockState(KINETIC_TILE, capState);
float interpolatedAngle = bearingTe.getInterpolatedAngle(partialTicks);
kineticRotationTransform(superBuffer, bearingTe, facing.getAxis(), interpolatedAngle, getWorld());
superBuffer.translate(x, y, z).renderInto(buffer);
if (!bearingTe.running)
return;
cacheConstructIfMissing(bearingTe.movingConstruct);
renderConstructFromCache(bearingTe.movingConstruct, bearingTe, x, y, z, partialTicks, buffer);
}
protected void cacheConstructIfMissing(RotationConstruct c) {
if (cachedConstructs == null)
cachedConstructs = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.SECONDS).build();
if (cachedConstructs.getIfPresent(c) != null)
return;
if (renderWorld == null || renderWorld.getWorld() != Minecraft.getInstance().world)
renderWorld = new PlacementSimulationWorld(Minecraft.getInstance().world);
BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher();
BlockModelRenderer blockRenderer = dispatcher.getBlockModelRenderer();
Random random = new Random();
BufferBuilder builder = new BufferBuilder(0);
builder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
builder.setTranslation(0, 0, 0);
for (BlockInfo info : c.blocks.values()) {
renderWorld.setBlockState(info.pos, info.state);
}
for (BlockInfo info : c.blocks.values()) {
IBakedModel originalModel = dispatcher.getModelForState(info.state);
blockRenderer.renderModel(renderWorld, originalModel, info.state, info.pos, builder, true, random, 42,
EmptyModelData.INSTANCE);
}
builder.finishDrawing();
renderWorld.clear();
cachedConstructs.put(c, new RotationConstructVertexBuffer(builder.getByteBuffer()));
}
protected void renderConstructFromCache(RotationConstruct c, MechanicalBearingTileEntity te, double x, double y,
double z, float partialTicks, BufferBuilder buffer) {
float zfightBonus = 1 / 128f;
Direction direction = te.getBlockState().get(BlockStateProperties.FACING);
Vec3i vec = direction.getDirectionVec();
buffer.putBulkData(cachedConstructs.getIfPresent(c).getTransformed(te, (float) (x) + vec.getX() * zfightBonus,
(float) (y) + vec.getY() * zfightBonus, (float) (z) + vec.getZ() * zfightBonus,
te.getInterpolatedAngle(partialTicks), direction.getAxis()));
}
@Override
protected BlockState getRenderedBlockState(KineticTileEntity te) {
return AllBlocks.SHAFT_HALF.get().getDefaultState().with(BlockStateProperties.FACING,
te.getBlockState().get(BlockStateProperties.FACING).getOpposite());
}
public static void invalidateCache() {
if (cachedConstructs != null)
cachedConstructs.invalidateAll();
}
}

View file

@ -1,212 +0,0 @@
package com.simibubi.create.modules.contraptions.receivers.constructs.bearing;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.simibubi.create.AllBlockTags;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.CreateConfig;
import com.simibubi.create.modules.contraptions.receivers.constructs.ChassisTileEntity;
import com.simibubi.create.modules.contraptions.receivers.constructs.RadialChassisBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.PistonBlock;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.ListNBT;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.template.Template.BlockInfo;
public class RotationConstruct {
protected Map<BlockPos, BlockInfo> blocks;
protected int sailBlocks;
public RotationConstruct() {
blocks = new HashMap<>();
sailBlocks = 0;
}
public static RotationConstruct getAttachedForRotating(World world, BlockPos pos, Direction direction) {
RotationConstruct construct = new RotationConstruct();
if (!construct.collectAttached(world, pos, direction))
return null;
return construct;
}
public int getSailBlocks() {
return sailBlocks;
}
protected boolean collectAttached(World world, BlockPos pos, Direction direction) {
if (isFrozen())
return false;
// Find chassis
List<BlockInfo> chassis = collectChassis(world, pos, direction);
if (chassis == null)
return false;
// Get single block
if (chassis.isEmpty()) {
BlockPos blockPos = pos.offset(direction);
BlockState state = world.getBlockState(pos.offset(direction));
if (state.getMaterial().isReplaceable() || state.isAir(world, blockPos))
return true;
if (state.getCollisionShape(world, blockPos).isEmpty())
return true;
if (!canRotate(world, blockPos, direction))
return false;
blocks.put(blockPos, new BlockInfo(blockPos.subtract(pos), state, null));
// Get attached blocks by chassis
} else {
List<BlockInfo> attachedBlocksByChassis = getAttachedBlocksByChassis(world, direction, chassis);
if (attachedBlocksByChassis == null)
return false;
attachedBlocksByChassis.forEach(info -> {
if (isSailBlock(info.state))
sailBlocks++;
blocks.put(info.pos, new BlockInfo(info.pos.subtract(pos), info.state, info.nbt));
});
}
return true;
}
private List<BlockInfo> getAttachedBlocksByChassis(World world, Direction direction, List<BlockInfo> chassis) {
List<BlockInfo> blocks = new ArrayList<>();
RadialChassisBlock def = (RadialChassisBlock) AllBlocks.ROTATION_CHASSIS.block;
for (BlockInfo chassisBlock : chassis) {
blocks.add(chassisBlock);
BlockState state = chassisBlock.state;
BlockPos currentPos = chassisBlock.pos;
TileEntity tileEntity = world.getTileEntity(currentPos);
if (!(tileEntity instanceof ChassisTileEntity))
return null;
int chassisRange = ((ChassisTileEntity) tileEntity).getRange();
Set<BlockPos> visited = new HashSet<>();
for (Direction facing : Direction.values()) {
if (facing.getAxis() == direction.getAxis())
continue;
if (!state.get(def.getGlueableSide(state, facing)))
continue;
BlockPos startPos = currentPos.offset(facing);
List<BlockPos> frontier = new LinkedList<>();
frontier.add(startPos);
CompoundNBT nbt = new CompoundNBT();
nbt.putInt("Range", chassisRange);
while (!frontier.isEmpty()) {
BlockPos searchPos = frontier.remove(0);
BlockState searchedState = world.getBlockState(searchPos);
if (visited.contains(searchPos))
continue;
if (!searchPos.withinDistance(currentPos, chassisRange + .5f))
continue;
if (searchedState.getMaterial().isReplaceable() || state.isAir(world, searchPos))
continue;
if (searchedState.getCollisionShape(world, searchPos).isEmpty())
continue;
if (!canRotate(world, searchPos, direction))
return null;
visited.add(searchPos);
blocks.add(new BlockInfo(searchPos, searchedState,
AllBlocks.ROTATION_CHASSIS.typeOf(searchedState) ? nbt : null));
for (Direction offset : Direction.values()) {
if (offset.getAxis() == direction.getAxis())
continue;
if (searchPos.equals(currentPos) && offset != facing)
continue;
frontier.add(searchPos.offset(offset));
}
}
}
}
return blocks;
}
private List<BlockInfo> collectChassis(World world, BlockPos pos, Direction direction) {
List<BlockInfo> chassis = new ArrayList<>();
for (int distance = 1; distance <= CreateConfig.parameters.maxChassisForRotation.get(); distance++) {
BlockPos currentPos = pos.offset(direction, distance);
if (!world.isBlockPresent(currentPos))
return chassis;
BlockState state = world.getBlockState(currentPos);
if (!AllBlocks.ROTATION_CHASSIS.typeOf(state))
return chassis;
if (direction.getAxis() != state.get(BlockStateProperties.AXIS))
return chassis;
chassis.add(new BlockInfo(currentPos, state, null));
}
return chassis;
}
private static boolean isSailBlock(BlockState state) {
return AllBlockTags.WINDMILL_SAILS.matches(state);
}
public CompoundNBT writeNBT() {
CompoundNBT nbt = new CompoundNBT();
ListNBT blocks = new ListNBT();
for (BlockInfo block : this.blocks.values()) {
CompoundNBT c = new CompoundNBT();
c.put("Block", NBTUtil.writeBlockState(block.state));
c.put("Pos", NBTUtil.writeBlockPos(block.pos));
if (block.nbt != null)
c.put("Data", block.nbt);
blocks.add(c);
}
nbt.put("Blocks", blocks);
return nbt;
}
public static RotationConstruct fromNBT(CompoundNBT nbt) {
RotationConstruct construct = new RotationConstruct();
nbt.getList("Blocks", 10).forEach(c -> {
CompoundNBT comp = (CompoundNBT) c;
BlockInfo info = new BlockInfo(NBTUtil.readBlockPos(comp.getCompound("Pos")),
NBTUtil.readBlockState(comp.getCompound("Block")),
comp.contains("Data") ? comp.getCompound("Data") : null);
construct.blocks.put(info.pos, info);
});
return construct;
}
private static boolean canRotate(World world, BlockPos pos, Direction direction) {
return PistonBlock.canPush(world.getBlockState(pos), world, pos, direction, true, direction)
|| AllBlocks.ROTATION_CHASSIS.typeOf(world.getBlockState(pos));
}
public static boolean isFrozen() {
return CreateConfig.parameters.freezeRotationConstructs.get();
}
}

View file

@ -1,42 +0,0 @@
package com.simibubi.create.modules.contraptions.receivers.constructs.bearing;
import java.nio.ByteBuffer;
import com.simibubi.create.foundation.utility.BufferManipulator;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction.Axis;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
public class RotationConstructVertexBuffer extends BufferManipulator {
public RotationConstructVertexBuffer(ByteBuffer original) {
super(original);
}
public ByteBuffer getTransformed(TileEntity te, float x, float y, float z, float angle, Axis axis) {
original.rewind();
mutable.rewind();
float cos = MathHelper.cos(angle);
float sin = MathHelper.sin(angle);
for (int vertex = 0; vertex < vertexCount(original); vertex++) {
float xL = getX(original, vertex) -.5f;
float yL = getY(original, vertex) -.5f;
float zL = getZ(original, vertex) -.5f;
float xL2 = rotateX(xL, yL, zL, sin, cos, axis) + .5f;
float yL2 = rotateY(xL, yL, zL, sin, cos, axis) + .5f;
float zL2 = rotateZ(xL, yL, zL, sin, cos, axis) + .5f;
putPos(mutable, vertex, xL2 + x, yL2 + y, zL2 + z);
BlockPos pos = new BlockPos(te.getPos().getX() + xL2, te.getPos().getY() + yL2, te.getPos().getZ() + zL2);
putLight(mutable, vertex, te.getWorld().getCombinedLight(pos, 0));
}
return mutable;
}
}

View file

@ -1,4 +1,4 @@
package com.simibubi.create.modules.contraptions.receivers.constructs;
package com.simibubi.create.modules.contraptions.receivers.contraptions;
import static com.simibubi.create.CreateConfig.parameters;
import static net.minecraft.state.properties.BlockStateProperties.AXIS;
@ -19,9 +19,14 @@ import org.apache.commons.lang3.tuple.MutablePair;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.CreateConfig;
import com.simibubi.create.modules.contraptions.receivers.SawBlock;
import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior.MovementContext;
import com.simibubi.create.modules.contraptions.receivers.constructs.mounted.MountedContraption;
import com.simibubi.create.modules.contraptions.receivers.constructs.piston.PistonContraption;
import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior.MovementContext;
import com.simibubi.create.modules.contraptions.receivers.contraptions.bearing.BearingContraption;
import com.simibubi.create.modules.contraptions.receivers.contraptions.chassis.AbstractChassisBlock;
import com.simibubi.create.modules.contraptions.receivers.contraptions.chassis.ChassisTileEntity;
import com.simibubi.create.modules.contraptions.receivers.contraptions.chassis.LinearChassisBlock;
import com.simibubi.create.modules.contraptions.receivers.contraptions.chassis.RadialChassisBlock;
import com.simibubi.create.modules.contraptions.receivers.contraptions.mounted.MountedContraption;
import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.PistonContraption;
import net.minecraft.block.BlockState;
import net.minecraft.block.FallingBlock;
@ -451,6 +456,8 @@ public class Contraption {
contraption = new PistonContraption();
if (type.equals("Mounted"))
contraption = new MountedContraption();
if (type.equals("Bearing"))
contraption = new BearingContraption();
contraption.readNBT(nbt);
return contraption;
}
@ -488,6 +495,8 @@ public class Contraption {
nbt.putString("Type", "Piston");
if (this instanceof MountedContraption)
nbt.putString("Type", "Mounted");
if (this instanceof BearingContraption)
nbt.putString("Type", "Bearing");
ListNBT blocks = new ListNBT();
for (BlockInfo block : this.blocks.values()) {

View file

@ -1,13 +1,12 @@
package com.simibubi.create.modules.contraptions.receivers.constructs.mounted;
package com.simibubi.create.modules.contraptions.receivers.contraptions;
import com.simibubi.create.AllEntities;
import com.simibubi.create.foundation.utility.VecHelper;
import com.simibubi.create.modules.contraptions.receivers.constructs.Contraption;
import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior;
import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior.MovementContext;
import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior.MovementContext;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.item.minecart.AbstractMinecartEntity;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.network.IPacket;
@ -31,11 +30,17 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD
protected BlockPos controllerPos;
protected IControlContraption controllerTE;
// Not synchronizing any of these yet
public float prevYaw;
public float prevPitch;
public float prevRoll;
public float yaw;
public float pitch;
public float roll;
// Mounted Contraptions
public float targetYaw;
public float targetPitch;
public float contraptionYaw;
public float contraptionPitch;
public ContraptionEntity(EntityType<?> entityTypeIn, World worldIn) {
super(entityTypeIn, worldIn);
@ -49,8 +54,8 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD
this(world);
this.contraption = contraption;
this.initialAngle = initialAngle;
this.prevRotationYaw = initialAngle;
this.contraptionYaw = initialAngle;
this.prevYaw = initialAngle;
this.yaw = initialAngle;
this.targetYaw = initialAngle;
}
@ -64,10 +69,9 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD
public void tick() {
super.tick();
attachToController();
Entity e = getRidingEntity();
if (e == null)
return;
else {
if (e != null) {
Vec3d movementVector = e.getMotion();
Vec3d motion = movementVector.normalize();
if (motion.length() > 0) {
@ -75,24 +79,29 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD
targetPitch = (float) ((Math.atan(motion.y) * 73.0D) / Math.PI * 180);
if (targetYaw < 0)
targetYaw += 360;
if (contraptionYaw < 0)
contraptionYaw += 360;
if (yaw < 0)
yaw += 360;
}
float speed = 0.2f;
prevRotationYaw = contraptionYaw;
contraptionYaw = angleLerp(speed, contraptionYaw, targetYaw);
prevRotationPitch = contraptionPitch;
contraptionPitch = angleLerp(speed, contraptionPitch, targetPitch);
prevYaw = yaw;
yaw = angleLerp(speed, yaw, targetYaw);
prevPitch = pitch;
pitch = angleLerp(speed, pitch, targetPitch);
tickActors(movementVector);
return;
}
prevYaw = yaw;
prevPitch = pitch;
prevRoll = roll;
}
public void tickActors(Vec3d movementVector) {
getContraption().getActors().forEach(pair -> {
MovementContext context = pair.right;
float deg = -contraptionYaw + initialAngle;
float deg = -yaw + initialAngle;
context.motion = VecHelper.rotate(movementVector, deg, Axis.Y);
if (context.world == null)
@ -120,8 +129,39 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD
});
}
public void moveTo(double x, double y, double z) {
move(x - posX, y - posY, z - posZ);
}
public void move(double x, double y, double z) {
// Collision and stuff
setPosition(posX + x, posY + y, posZ + z);
}
public void rotateTo(double roll, double yaw, double pitch) {
rotate(getShortestAngleDiff(this.roll, roll), getShortestAngleDiff(this.yaw, yaw),
getShortestAngleDiff(this.pitch, pitch));
}
public void rotate(double roll, double yaw, double pitch) {
// Collision and stuff
this.yaw += yaw;
this.pitch += pitch;
this.roll += roll;
}
@Override
public void setPosition(double x, double y, double z) {
Entity e = getRidingEntity();
if (e != null && e instanceof AbstractMinecartEntity) {
x -= .5;
z -= .5;
}
this.posX = x;
this.posY = y;
this.posZ = z;
@ -134,25 +174,37 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD
}
}
@Override
public void stopRiding() {
super.stopRiding();
if (!world.isRemote)
disassemble();
}
public static float yawFromMotion(Vec3d motion) {
return (float) ((Math.PI / 2 - Math.atan2(motion.z, motion.x)) / Math.PI * 180);
}
public float getYaw(float partialTicks) {
float yaw = contraptionYaw;
return (partialTicks == 1.0F ? yaw : angleLerp(partialTicks, this.prevRotationYaw, yaw)) - initialAngle;
return (partialTicks == 1.0F ? yaw : angleLerp(partialTicks, prevYaw, yaw)) - initialAngle;
}
public float getPitch(float partialTicks) {
float pitch = contraptionPitch;
return partialTicks == 1.0F ? pitch : angleLerp(partialTicks, this.prevRotationPitch, pitch);
return partialTicks == 1.0F ? pitch : angleLerp(partialTicks, prevPitch, pitch);
}
public float getRoll(float partialTicks) {
return partialTicks == 1.0F ? roll : angleLerp(partialTicks, prevRoll, roll);
}
private float angleLerp(float pct, float current, float target) {
return current + getShortestAngleDiff(current, target) * pct;
}
private float getShortestAngleDiff(double current, double target) {
current = current % 360;
target = target % 360;
float shortest_angle = ((((target - current) % 360) + 540) % 360) - 180;
return current + shortest_angle * pct;
return (float) (((((target - current) % 360) + 540) % 360) - 180);
}
public static EntityType.Builder<?> build(EntityType.Builder<?> builder) {
@ -171,8 +223,8 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD
initialAngle = compound.getFloat("InitialAngle");
if (compound.contains("Controller"))
controllerPos = NBTUtil.readBlockPos(compound.getCompound("Controller"));
prevRotationYaw = initialAngle;
contraptionYaw = initialAngle;
prevYaw = initialAngle;
yaw = initialAngle;
targetYaw = initialAngle;
}
@ -216,8 +268,7 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD
public void disassemble() {
if (getContraption() != null)
getContraption().disassemble(world, new BlockPos(getPositionVec().add(.5, .5, .5)), contraptionYaw,
contraptionPitch);
getContraption().disassemble(world, new BlockPos(getPositionVec().add(.5, .5, .5)), yaw, pitch);
remove();
}

View file

@ -1,8 +1,8 @@
package com.simibubi.create.modules.contraptions.receivers.constructs.mounted;
package com.simibubi.create.modules.contraptions.receivers.contraptions;
import com.mojang.blaze3d.platform.GlStateManager;
import com.simibubi.create.foundation.utility.TessellatorHelper;
import com.simibubi.create.modules.contraptions.receivers.constructs.ContraptionRenderer;
import com.simibubi.create.foundation.utility.VecHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
@ -13,6 +13,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.item.minecart.AbstractMinecartEntity;
import net.minecraft.util.Direction.Axis;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
@ -37,11 +38,11 @@ public class ContraptionEntityRenderer extends EntityRenderer<ContraptionEntity>
GlStateManager.pushMatrix();
float angleYaw = (float) (entity.getYaw(partialTicks) / 180 * Math.PI);
float anglePitch = (float) (entity.getPitch(partialTicks) / 180 * Math.PI);
float angleRoll = (float) (entity.getRoll(partialTicks) / 180 * Math.PI);
Entity ridingEntity = entity.getRidingEntity();
if (ridingEntity != null && ridingEntity instanceof AbstractMinecartEntity) {
AbstractMinecartEntity cart = (AbstractMinecartEntity) ridingEntity;
GlStateManager.translated(0, .5, 0);
long i = (long) entity.getEntityId() * 493286711L;
i = i * i * 4392167121L + i * 98761L;
@ -73,15 +74,17 @@ public class ContraptionEntityRenderer extends EntityRenderer<ContraptionEntity>
}
// BlockPos anchor = entity.getContraption().getAnchor();
// Vec3d rotationOffset = VecHelper.getCenterOf(anchor);
Vec3d rotationOffset = VecHelper.getCenterOf(BlockPos.ZERO);
// Vec3d offset = VecHelper.getCenterOf(anchor).scale(-1);
TessellatorHelper.prepareFastRender();
TessellatorHelper.begin(DefaultVertexFormats.BLOCK);
ContraptionRenderer.render(entity.world, entity.getContraption(), superByteBuffer -> {
// superByteBuffer.translate(-rotationOffset.x, -rotationOffset.y, -rotationOffset.z);
superByteBuffer.translate(-rotationOffset.x, -rotationOffset.y, -rotationOffset.z);
superByteBuffer.rotate(Axis.X, angleRoll);
superByteBuffer.rotate(Axis.Y, angleYaw);
superByteBuffer.rotate(Axis.Z, anglePitch);
superByteBuffer.translate(rotationOffset.x, rotationOffset.y, rotationOffset.z);
superByteBuffer.translate(x, y, z);
superByteBuffer.offsetLighting(-x + entity.posX, -y + entity.posY, -z + entity.posZ);

View file

@ -1,4 +1,4 @@
package com.simibubi.create.modules.contraptions.receivers.constructs;
package com.simibubi.create.modules.contraptions.receivers.contraptions;
import java.util.Random;
import java.util.function.Consumer;
@ -10,7 +10,7 @@ import com.simibubi.create.CreateClient;
import com.simibubi.create.foundation.utility.PlacementSimulationWorld;
import com.simibubi.create.foundation.utility.SuperByteBuffer;
import com.simibubi.create.foundation.utility.SuperByteBufferCache.Compartment;
import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior.MovementContext;
import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior.MovementContext;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockModelRenderer;

View file

@ -1,4 +1,4 @@
package com.simibubi.create.modules.contraptions.receivers.constructs.mounted;
package com.simibubi.create.modules.contraptions.receivers.contraptions;
public interface IControlContraption {

View file

@ -1,8 +1,8 @@
package com.simibubi.create.modules.contraptions.receivers.constructs;
package com.simibubi.create.modules.contraptions.receivers.contraptions;
import com.simibubi.create.foundation.utility.SuperByteBuffer;
import com.simibubi.create.foundation.utility.VecHelper;
import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonTileEntity;
import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.MechanicalPistonTileEntity;
import net.minecraft.block.BlockState;
import net.minecraft.nbt.CompoundNBT;

View file

@ -0,0 +1,53 @@
package com.simibubi.create.modules.contraptions.receivers.contraptions.bearing;
import com.simibubi.create.AllBlockTags;
import com.simibubi.create.modules.contraptions.receivers.contraptions.Contraption;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.template.Template.BlockInfo;
public class BearingContraption extends Contraption {
protected int sailBlocks;
protected Direction facing;
public static BearingContraption assembleBearingAt(World world, BlockPos pos, Direction direction) {
if (isFrozen())
return null;
BearingContraption construct = new BearingContraption();
construct.facing = direction;
if (!construct.searchMovedStructure(world, pos.offset(direction), direction))
return null;
return construct;
}
@Override
public void add(BlockPos pos, BlockInfo block) {
if (AllBlockTags.WINDMILL_SAILS.matches(block.state))
sailBlocks++;
super.add(pos, block);
}
@Override
public CompoundNBT writeNBT() {
CompoundNBT tag = super.writeNBT();
tag.putInt("Sails", sailBlocks);
tag.putInt("facing", facing.getIndex());
return tag;
}
@Override
public void readNBT(CompoundNBT tag) {
sailBlocks = tag.getInt("Sails");
facing = Direction.byIndex(tag.getInt("Facing"));
super.readNBT(tag);
}
public int getSailBlocks() {
return sailBlocks;
}
}

View file

@ -1,4 +1,4 @@
package com.simibubi.create.modules.contraptions.receivers.constructs.bearing;
package com.simibubi.create.modules.contraptions.receivers.contraptions.bearing;
import com.simibubi.create.foundation.block.IWithTileEntity;
import com.simibubi.create.modules.contraptions.base.DirectionalKineticBlock;

View file

@ -1,25 +1,23 @@
package com.simibubi.create.modules.contraptions.receivers.constructs.bearing;
package com.simibubi.create.modules.contraptions.receivers.contraptions.bearing;
import com.simibubi.create.AllTileEntities;
import com.simibubi.create.modules.contraptions.base.GeneratingKineticTileEntity;
import com.simibubi.create.modules.contraptions.receivers.constructs.ChassisTileEntity;
import com.simibubi.create.modules.contraptions.receivers.contraptions.Contraption;
import com.simibubi.create.modules.contraptions.receivers.contraptions.ContraptionEntity;
import com.simibubi.create.modules.contraptions.receivers.contraptions.IControlContraption;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.gen.feature.template.Template.BlockInfo;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity {
public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity implements IControlContraption {
protected RotationConstruct movingConstruct;
protected ContraptionEntity movedContraption;
protected float angle;
protected boolean running;
protected boolean assembleNextTick;
@ -30,17 +28,6 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity {
isWindmill = false;
}
@Override
public AxisAlignedBB getRenderBoundingBox() {
return INFINITE_EXTENT_AABB;
}
@Override
@OnlyIn(Dist.CLIENT)
public double getMaxRenderDistanceSquared() {
return super.getMaxRenderDistanceSquared() * 16;
}
@Override
public float getAddedStressCapacity() {
return isWindmill ? super.getAddedStressCapacity() : 0;
@ -77,7 +64,7 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity {
public float getGeneratedSpeed() {
if (!running || !isWindmill)
return 0;
int sails = movingConstruct.getSailBlocks();
int sails = ((BearingContraption) movedContraption.getContraption()).getSailBlocks();
return MathHelper.clamp(sails, 0, 128);
}
@ -86,9 +73,6 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity {
tag.putBoolean("Running", running);
tag.putBoolean("Windmill", isWindmill);
tag.putFloat("Angle", angle);
if (running && !RotationConstruct.isFrozen())
tag.put("Construct", movingConstruct.writeNBT());
return super.write(tag);
}
@ -97,15 +81,10 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity {
running = tag.getBoolean("Running");
isWindmill = tag.getBoolean("Windmill");
angle = tag.getFloat("Angle");
if (running && !RotationConstruct.isFrozen())
movingConstruct = RotationConstruct.fromNBT(tag.getCompound("Construct"));
super.read(tag);
}
public float getInterpolatedAngle(float partialTicks) {
if (RotationConstruct.isFrozen())
return 0;
return MathHelper.lerp(partialTicks, angle, angle + getAngularSpeed());
}
@ -123,19 +102,23 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity {
Direction direction = getBlockState().get(BlockStateProperties.FACING);
// Collect Construct
movingConstruct = RotationConstruct.getAttachedForRotating(getWorld(), getPos(), direction);
if (movingConstruct == null)
BearingContraption contraption = BearingContraption.assembleBearingAt(world, pos, direction);
if (contraption == null)
return;
if (isWindmill && movingConstruct.getSailBlocks() == 0)
if (isWindmill && contraption.getSailBlocks() == 0)
return;
movedContraption = new ContraptionEntity(world, contraption, 0).controlledBy(this);
BlockPos anchor = pos.offset(direction);
movedContraption.setPosition(anchor.getX(), anchor.getY(), anchor.getZ());
world.addEntity(movedContraption);
// Run
running = true;
angle = 0;
sendData();
for (BlockInfo info : movingConstruct.blocks.values()) {
getWorld().setBlockState(info.pos.add(pos), Blocks.AIR.getDefaultState(), 67);
for (BlockInfo info : contraption.blocks.values()) {
getWorld().setBlockState(info.pos.add(contraption.getAnchor()), Blocks.AIR.getDefaultState(), 67);
}
updateGeneratedRotation();
@ -145,24 +128,9 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity {
if (!running)
return;
for (BlockInfo block : movingConstruct.blocks.values()) {
BlockPos targetPos = block.pos.add(pos);
BlockState state = block.state;
for (Direction face : Direction.values())
state = state.updatePostPlacement(face, world.getBlockState(targetPos.offset(face)), world, targetPos,
targetPos.offset(face));
world.destroyBlock(targetPos, world.getBlockState(targetPos).getCollisionShape(world, targetPos).isEmpty());
getWorld().setBlockState(targetPos, state, 3);
TileEntity tileEntity = world.getTileEntity(targetPos);
if (tileEntity != null && block.nbt != null) {
((ChassisTileEntity) tileEntity).setRange(block.nbt.getInt("Range"));
}
}
movedContraption.disassemble();
movedContraption = null;
running = false;
movingConstruct = null;
angle = 0;
updateGeneratedRotation();
sendData();
@ -172,14 +140,15 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity {
public void tick() {
super.tick();
if (running && RotationConstruct.isFrozen())
if (running && Contraption.isFrozen())
disassembleConstruct();
if (!world.isRemote && assembleNextTick) {
assembleNextTick = false;
if (running) {
boolean canDisassemble = Math.abs(angle) < Math.PI / 4f || Math.abs(angle) > 7 * Math.PI / 4f;
if (speed == 0 && (canDisassemble || movingConstruct == null || movingConstruct.blocks.isEmpty())) {
if (speed == 0 && (canDisassemble || movedContraption == null
|| movedContraption.getContraption().blocks.isEmpty())) {
disassembleConstruct();
}
return;
@ -197,6 +166,26 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity {
float angularSpeed = getAngularSpeed();
float newAngle = angle + angularSpeed;
angle = (float) (newAngle % (2 * Math.PI));
applyRotation();
}
private void applyRotation() {
if (movedContraption != null) {
Direction direction = getBlockState().get(BlockStateProperties.FACING);
Vec3d vec = new Vec3d(1, 1, 1).scale(angle * 180 / Math.PI).mul(new Vec3d(direction.getDirectionVec()));
movedContraption.rotateTo(-vec.x, vec.y, -vec.z);
}
}
@Override
public void attach(ContraptionEntity contraption) {
if (contraption.getContraption() instanceof BearingContraption) {
this.movedContraption = contraption;
BlockPos anchor = pos.offset(getBlockState().get(BlockStateProperties.FACING));
movedContraption.setPosition(anchor.getX(), anchor.getY(), anchor.getZ());
if (!world.isRemote)
sendData();
}
}
}

View file

@ -0,0 +1,38 @@
package com.simibubi.create.modules.contraptions.receivers.contraptions.bearing;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.CreateClient;
import com.simibubi.create.foundation.utility.SuperByteBuffer;
import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
import com.simibubi.create.modules.contraptions.base.KineticTileEntityRenderer;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction;
public class MechanicalBearingTileEntityRenderer extends KineticTileEntityRenderer {
@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);
MechanicalBearingTileEntity bearingTe = (MechanicalBearingTileEntity) te;
final Direction facing = te.getBlockState().get(BlockStateProperties.FACING);
BlockState capState = AllBlocks.MECHANICAL_BEARING_TOP.get().getDefaultState().with(BlockStateProperties.FACING,
facing);
SuperByteBuffer superBuffer = CreateClient.bufferCache.renderBlockState(KINETIC_TILE, capState);
float interpolatedAngle = bearingTe.getInterpolatedAngle(partialTicks);
kineticRotationTransform(superBuffer, bearingTe, facing.getAxis(), interpolatedAngle, getWorld());
superBuffer.translate(x, y, z).renderInto(buffer);
}
@Override
protected BlockState getRenderedBlockState(KineticTileEntity te) {
return AllBlocks.SHAFT_HALF.get().getDefaultState().with(BlockStateProperties.FACING,
te.getBlockState().get(BlockStateProperties.FACING).getOpposite());
}
}

View file

@ -1,4 +1,4 @@
package com.simibubi.create.modules.contraptions.receivers.constructs;
package com.simibubi.create.modules.contraptions.receivers.contraptions.chassis;
import java.util.List;

View file

@ -1,4 +1,4 @@
package com.simibubi.create.modules.contraptions.receivers.constructs;
package com.simibubi.create.modules.contraptions.receivers.contraptions.chassis;
import static com.simibubi.create.CreateConfig.parameters;

View file

@ -1,4 +1,4 @@
package com.simibubi.create.modules.contraptions.receivers.constructs;
package com.simibubi.create.modules.contraptions.receivers.contraptions.chassis;
import com.simibubi.create.foundation.packet.TileEntityConfigurationPacket;

View file

@ -1,4 +1,4 @@
package com.simibubi.create.modules.contraptions.receivers.constructs;
package com.simibubi.create.modules.contraptions.receivers.contraptions.chassis;
import com.google.common.collect.ImmutableList;
import com.simibubi.create.AllBlocks;

View file

@ -1,4 +1,4 @@
package com.simibubi.create.modules.contraptions.receivers.constructs;
package com.simibubi.create.modules.contraptions.receivers.contraptions.chassis;
import com.simibubi.create.foundation.utility.Lang;

View file

@ -1,15 +1,15 @@
package com.simibubi.create.modules.contraptions.receivers.constructs.mounted;
package com.simibubi.create.modules.contraptions.receivers.contraptions.mounted;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.foundation.block.RenderUtilityBlock;
import com.simibubi.create.modules.contraptions.receivers.constructs.Contraption;
import com.simibubi.create.modules.contraptions.receivers.contraptions.Contraption;
import com.simibubi.create.modules.contraptions.receivers.contraptions.ContraptionEntity;
import net.minecraft.block.AbstractRailBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.material.PushReaction;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.minecart.AbstractMinecartEntity;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.BooleanProperty;
@ -84,17 +84,8 @@ public class CartAssemblerBlock extends AbstractRailBlock {
protected void disassemble(World world, BlockPos pos, AbstractMinecartEntity cart) {
if (cart.getPassengers().isEmpty())
return;
Entity entity = cart.getPassengers().get(0);
if (!(entity instanceof ContraptionEntity))
if (!(cart.getPassengers().get(0) instanceof ContraptionEntity))
return;
Contraption contraption = ((ContraptionEntity) entity).getContraption();
if (contraption == null)
return;
contraption.disassemble(world, pos.subtract(contraption.getAnchor()), 0, 0, (targetPos, state) -> {
return targetPos.equals(pos);
});
cart.removePassengers();
}

View file

@ -1,15 +1,15 @@
package com.simibubi.create.modules.contraptions.receivers.constructs.mounted;
package com.simibubi.create.modules.contraptions.receivers.contraptions.mounted;
import static com.simibubi.create.modules.contraptions.receivers.constructs.mounted.CartAssemblerBlock.RAIL_SHAPE;
import static com.simibubi.create.modules.contraptions.receivers.contraptions.mounted.CartAssemblerBlock.RAIL_SHAPE;
import java.util.List;
import org.apache.commons.lang3.tuple.MutablePair;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.modules.contraptions.receivers.constructs.Contraption;
import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior.MovementContext;
import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior.MoverType;
import com.simibubi.create.modules.contraptions.receivers.contraptions.Contraption;
import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior.MovementContext;
import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior.MoverType;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
@ -21,6 +21,7 @@ import net.minecraft.util.Direction.Axis;
import net.minecraft.util.Direction.AxisDirection;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.template.Template.BlockInfo;
@ -45,10 +46,9 @@ public class MountedContraption extends Contraption {
null));
for (BlockInfo block : contraption.blocks.values()) {
BlockPos startPos = pos;
if (startPos.equals(block.pos))
if (BlockPos.ZERO.equals(block.pos))
continue;
world.setBlockState(block.pos, Blocks.AIR.getDefaultState(), 67);
world.setBlockState(block.pos.add(pos), Blocks.AIR.getDefaultState(), 67);
}
for (MutablePair<BlockInfo, MovementContext> pair : contraption.getActors()) {
@ -83,4 +83,9 @@ public class MountedContraption extends Contraption {
return capture;
}
@Override
public void disassemble(IWorld world, BlockPos offset, float yaw, float pitch) {
super.disassemble(world, offset, yaw, pitch, (pos, state) -> AllBlocks.MINECART_ANCHOR.typeOf(state));
}
}

View file

@ -1,4 +1,4 @@
package com.simibubi.create.modules.contraptions.receivers.constructs.piston;
package com.simibubi.create.modules.contraptions.receivers.contraptions.piston;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.CreateConfig;

View file

@ -1,10 +1,10 @@
package com.simibubi.create.modules.contraptions.receivers.constructs.piston;
package com.simibubi.create.modules.contraptions.receivers.contraptions.piston;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.CreateConfig;
import com.simibubi.create.foundation.block.IWithoutBlockItem;
import com.simibubi.create.foundation.block.ProperDirectionalBlock;
import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonBlock.PistonState;
import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.MechanicalPistonBlock.PistonState;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;

View file

@ -1,28 +1,25 @@
package com.simibubi.create.modules.contraptions.receivers.constructs.piston;
package com.simibubi.create.modules.contraptions.receivers.contraptions.piston;
import org.apache.commons.lang3.tuple.MutablePair;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllTileEntities;
import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior.MovementContext;
import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior.MoverType;
import com.simibubi.create.modules.contraptions.receivers.constructs.mounted.ContraptionEntity;
import com.simibubi.create.modules.contraptions.receivers.constructs.mounted.IControlContraption;
import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonBlock.PistonState;
import com.simibubi.create.modules.contraptions.receivers.contraptions.ContraptionEntity;
import com.simibubi.create.modules.contraptions.receivers.contraptions.IControlContraption;
import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior.MovementContext;
import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior.MoverType;
import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.MechanicalPistonBlock.PistonState;
import net.minecraft.block.Blocks;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction;
import net.minecraft.util.Direction.Axis;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.gen.feature.template.Template.BlockInfo;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public class MechanicalPistonTileEntity extends KineticTileEntity implements IControlContraption {
@ -52,17 +49,6 @@ public class MechanicalPistonTileEntity extends KineticTileEntity implements ICo
super.remove();
}
@Override
public AxisAlignedBB getRenderBoundingBox() {
return INFINITE_EXTENT_AABB;
}
@Override
@OnlyIn(Dist.CLIENT)
public double getMaxRenderDistanceSquared() {
return super.getMaxRenderDistanceSquared() * 16;
}
@Override
public CompoundNBT write(CompoundNBT tag) {
tag.putBoolean("Running", running);

View file

@ -1,4 +1,4 @@
package com.simibubi.create.modules.contraptions.receivers.constructs.piston;
package com.simibubi.create.modules.contraptions.receivers.contraptions.piston;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.modules.contraptions.base.IRotate;

View file

@ -1,3 +1,4 @@
package com.simibubi.create.modules.contraptions.receivers.contraptions.piston;
/*package com.simibubi.create.modules.contraptions.receivers.constructs.piston;
import java.util.ArrayList;

View file

@ -1,4 +1,4 @@
package com.simibubi.create.modules.contraptions.receivers.constructs.piston;
package com.simibubi.create.modules.contraptions.receivers.contraptions.piston;
import static com.simibubi.create.AllBlocks.MECHANICAL_PISTON_HEAD;
import static com.simibubi.create.AllBlocks.PISTON_POLE;
@ -10,8 +10,8 @@ import java.util.ArrayList;
import java.util.List;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.modules.contraptions.receivers.constructs.Contraption;
import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonBlock.PistonState;
import com.simibubi.create.modules.contraptions.receivers.contraptions.Contraption;
import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.MechanicalPistonBlock.PistonState;
import net.minecraft.block.BlockState;
import net.minecraft.nbt.CompoundNBT;

View file

@ -1,9 +1,9 @@
package com.simibubi.create.modules.contraptions.receivers.constructs.piston;
package com.simibubi.create.modules.contraptions.receivers.contraptions.piston;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.CreateConfig;
import com.simibubi.create.foundation.block.ProperDirectionalBlock;
import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonBlock.PistonState;
import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.MechanicalPistonBlock.PistonState;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;

View file

@ -4,7 +4,7 @@ import java.util.Random;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.foundation.block.ProperDirectionalBlock;
import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior;
import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;