Temporary turnaround
- Fixed Minecart Contraption Item's initial orientation being incorrect inconsistent in certain situations
This commit is contained in:
parent
ecfa554c05
commit
f8111205b3
5 changed files with 43 additions and 34 deletions
|
@ -239,8 +239,7 @@ public abstract class Contraption {
|
|||
continue;
|
||||
}
|
||||
subContraption.removeBlocksFromWorld(world, BlockPos.ZERO);
|
||||
OrientedContraptionEntity movedContraption =
|
||||
OrientedContraptionEntity.create(world, subContraption, Optional.of(face));
|
||||
OrientedContraptionEntity movedContraption = OrientedContraptionEntity.create(world, subContraption, face);
|
||||
BlockPos anchor = blockFace.getConnectedPos();
|
||||
movedContraption.setPosition(anchor.getX() + .5f, anchor.getY(), anchor.getZ() + .5f);
|
||||
world.addEntity(movedContraption);
|
||||
|
|
|
@ -85,17 +85,17 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity {
|
|||
}
|
||||
|
||||
public static OrientedContraptionEntity create(World world, Contraption contraption,
|
||||
Optional<Direction> initialOrientation) {
|
||||
Direction initialOrientation) {
|
||||
OrientedContraptionEntity entity =
|
||||
new OrientedContraptionEntity(AllEntityTypes.ORIENTED_CONTRAPTION.get(), world);
|
||||
entity.setContraption(contraption);
|
||||
initialOrientation.ifPresent(entity::setInitialOrientation);
|
||||
entity.setInitialOrientation(initialOrientation);
|
||||
entity.startAtInitialYaw();
|
||||
return entity;
|
||||
}
|
||||
|
||||
public static OrientedContraptionEntity createAtYaw(World world, Contraption contraption,
|
||||
Optional<Direction> initialOrientation, float initialYaw) {
|
||||
Direction initialOrientation, float initialYaw) {
|
||||
OrientedContraptionEntity entity = create(world, contraption, initialOrientation);
|
||||
entity.startAtYaw(initialYaw);
|
||||
entity.manuallyPlaced = true;
|
||||
|
|
|
@ -2,8 +2,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.mo
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -11,21 +9,12 @@ import javax.annotation.Nullable;
|
|||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllShapes;
|
||||
import com.simibubi.create.AllTileEntities;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerTileEntity.CartMovementMode;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.train.CouplingHandler;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.train.capability.CapabilityMinecartController;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.train.capability.MinecartController;
|
||||
import com.simibubi.create.content.contraptions.components.tracks.ControllerRailBlock;
|
||||
import com.simibubi.create.content.contraptions.wrench.IWrenchable;
|
||||
import com.simibubi.create.content.schematics.ISpecialBlockItemRequirement;
|
||||
import com.simibubi.create.content.schematics.ItemRequirement;
|
||||
import com.simibubi.create.content.schematics.ItemRequirement.ItemUseType;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.utility.Couple;
|
||||
import com.simibubi.create.foundation.utility.Iterate;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
|
||||
import net.minecraft.block.AbstractRailBlock;
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -41,7 +30,6 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.loot.LootContext;
|
||||
import net.minecraft.loot.LootParameters;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.pathfinding.PathType;
|
||||
import net.minecraft.state.BooleanProperty;
|
||||
import net.minecraft.state.EnumProperty;
|
||||
|
@ -60,17 +48,14 @@ import net.minecraft.util.SoundCategory;
|
|||
import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.util.math.shapes.VoxelShapes;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.util.math.vector.Vector3i;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
|
||||
public class CartAssemblerBlock extends AbstractRailBlock
|
||||
implements ITE<CartAssemblerTileEntity>, IWrenchable, ISpecialBlockItemRequirement {
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.mounted;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
|
@ -27,10 +24,15 @@ import com.simibubi.create.foundation.utility.Iterate;
|
|||
import com.simibubi.create.foundation.utility.Lang;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.minecart.AbstractMinecartEntity;
|
||||
import net.minecraft.entity.item.minecart.FurnaceMinecartEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.state.properties.RailShape;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
|
@ -42,7 +44,11 @@ import net.minecraft.util.math.vector.Vector3d;
|
|||
import net.minecraft.util.math.vector.Vector3i;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
|
||||
@EventBusSubscriber
|
||||
public class CartAssemblerTileEntity extends SmartTileEntity implements IDisplayAssemblyExceptions {
|
||||
private static final int assemblyCooldown = 8;
|
||||
|
||||
|
@ -51,6 +57,7 @@ public class CartAssemblerTileEntity extends SmartTileEntity implements IDisplay
|
|||
protected AssemblyException lastException;
|
||||
|
||||
protected AbstractMinecartEntity cartToAssemble;
|
||||
protected Direction cartInitialOrientation = Direction.NORTH;
|
||||
|
||||
public CartAssemblerTileEntity(TileEntityType<? extends CartAssemblerTileEntity> type) {
|
||||
super(type);
|
||||
|
@ -140,8 +147,8 @@ public class CartAssemblerTileEntity extends SmartTileEntity implements IDisplay
|
|||
}
|
||||
|
||||
boolean couplingFound = contraption.connectedCart != null;
|
||||
Optional<Direction> initialOrientation = cart.getMotion()
|
||||
.length() < 1 / 512f ? Optional.empty() : Optional.of(cart.getAdjustedHorizontalFacing());
|
||||
Direction initialOrientation = cart.getMotion()
|
||||
.length() < 1 / 512f ? cartInitialOrientation : cart.getAdjustedHorizontalFacing();
|
||||
|
||||
if (couplingFound) {
|
||||
cart.setPosition(pos.getX() + .5f, pos.getY(), pos.getZ() + .5f);
|
||||
|
@ -155,9 +162,8 @@ public class CartAssemblerTileEntity extends SmartTileEntity implements IDisplay
|
|||
contraption.expandBoundsAroundAxis(Axis.Y);
|
||||
|
||||
if (couplingFound) {
|
||||
Vector3d diff = contraption.connectedCart.getPositionVec()
|
||||
.subtract(cart.getPositionVec());
|
||||
initialOrientation = Optional.of(Direction.fromAngle(MathHelper.atan2(diff.z, diff.x) * 180 / Math.PI));
|
||||
Vector3d diff = contraption.connectedCart.getPositionVec().subtract(cart.getPositionVec());
|
||||
initialOrientation = Direction.fromAngle(MathHelper.atan2(diff.z, diff.x) * 180 / Math.PI);
|
||||
}
|
||||
|
||||
OrientedContraptionEntity entity = OrientedContraptionEntity.create(world, contraption, initialOrientation);
|
||||
|
@ -314,4 +320,27 @@ public class CartAssemblerTileEntity extends SmartTileEntity implements IDisplay
|
|||
public boolean isMinecartUpdateValid() {
|
||||
return ticksSinceMinecartUpdate >= assemblyCooldown;
|
||||
}
|
||||
|
||||
// TODO: Remove these methods once we give Cart Assemblers directionality
|
||||
protected void setCartInitialOrientation(Direction direction) {
|
||||
cartInitialOrientation = direction;
|
||||
}
|
||||
@SubscribeEvent
|
||||
public static void getOrientationOfStationaryCart(PlayerInteractEvent.RightClickBlock event) {
|
||||
PlayerEntity player = event.getPlayer();
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
Item item = event.getItemStack().getItem();
|
||||
if (item != Items.MINECART && item != Items.CHEST_MINECART && item != Items.FURNACE_MINECART)
|
||||
return;
|
||||
Block block = event.getWorld().getBlockState(event.getPos()).getBlock();
|
||||
if (!(block instanceof CartAssemblerBlock))
|
||||
return;
|
||||
CartAssemblerTileEntity te = ((CartAssemblerBlock) block).getTileEntity(event.getWorld(), event.getPos());
|
||||
if (te == null)
|
||||
return;
|
||||
|
||||
te.setCartInitialOrientation(player.getHorizontalFacing());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -173,10 +173,7 @@ public class MinecartContraptionItem extends Item {
|
|||
if (tag.contains("Contraption")) {
|
||||
CompoundNBT contraptionTag = tag.getCompound("Contraption");
|
||||
|
||||
Optional<Direction> intialOrientation = Optional.empty();
|
||||
if (contraptionTag.contains("InitialOrientation"))
|
||||
intialOrientation =
|
||||
Optional.of(NBTHelper.readEnum(contraptionTag, "InitialOrientation", Direction.class));
|
||||
Direction intialOrientation = NBTHelper.readEnum(contraptionTag, "InitialOrientation", Direction.class);
|
||||
|
||||
Contraption mountedContraption = Contraption.fromNBT(world, contraptionTag, false);
|
||||
OrientedContraptionEntity contraptionEntity =
|
||||
|
@ -287,7 +284,6 @@ public class MinecartContraptionItem extends Item {
|
|||
tag.remove("Pos");
|
||||
tag.remove("Motion");
|
||||
|
||||
if (entity.isInitialOrientationPresent())
|
||||
NBTHelper.writeEnum(tag, "InitialOrientation", entity.getInitialOrientation());
|
||||
|
||||
stack.getOrCreateTag()
|
||||
|
|
Loading…
Reference in a new issue