Compare, but do not fall

- Yet another attempt at preventing elevator fall damage
- Flexcrate now has comparator output
- Basin now has comparator output
- Kinetic Gauges now have comparator output
- Stress Gauge -> Stressometer
This commit is contained in:
simibubi 2020-03-15 12:42:36 +01:00
parent 0e0148cbb6
commit 1edda9b564
13 changed files with 166 additions and 24 deletions

View File

@ -11,6 +11,7 @@ import com.simibubi.create.foundation.item.AbstractToolItem;
import com.simibubi.create.foundation.packet.NbtPacket;
import com.simibubi.create.foundation.packet.SimplePacketBase;
import com.simibubi.create.foundation.utility.ServerSpeedProvider;
import com.simibubi.create.modules.contraptions.components.contraptions.CancelPlayerFallPacket;
import com.simibubi.create.modules.contraptions.components.contraptions.ContraptionStallPacket;
import com.simibubi.create.modules.contraptions.relays.advanced.sequencer.ConfigureSequencedGearshiftPacket;
import com.simibubi.create.modules.curiosities.symmetry.SymmetryEffectPacket;
@ -41,6 +42,7 @@ public enum AllPackets {
CONFIGURE_FILTER(FilterScreenPacket.class, FilterScreenPacket::new),
CONFIGURE_FILTERING_AMOUNT(FilteringCountUpdatePacket.class, FilteringCountUpdatePacket::new),
CONFIGURE_SCROLLABLE(ScrollValueUpdatePacket.class, ScrollValueUpdatePacket::new),
CANCEL_FALL(CancelPlayerFallPacket.class, CancelPlayerFallPacket::new),
// Server to Client
SYMMETRY_EFFECT(SymmetryEffectPacket.class, SymmetryEffectPacket::new),

View File

@ -5,6 +5,8 @@ import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import javax.annotation.Nullable;
import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.commons.lang3.tuple.Pair;
@ -13,6 +15,7 @@ import com.simibubi.create.config.AllConfigs;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
@ -55,6 +58,33 @@ public class ItemHelper {
return true;
}
public static int calcRedstoneFromInventory(@Nullable IItemHandler inv) {
if (inv == null)
return 0;
int i = 0;
float f = 0.0F;
int totalSlots = inv.getSlots();
for (int j = 0; j < inv.getSlots(); ++j) {
int slotLimit = inv.getSlotLimit(j);
if (slotLimit == 0) {
totalSlots--;
continue;
}
ItemStack itemstack = inv.getStackInSlot(j);
if (!itemstack.isEmpty()) {
f += (float) itemstack.getCount() / (float) Math.min(slotLimit, itemstack.getMaxStackSize());
++i;
}
}
if (totalSlots == 0)
return 0;
f = f / totalSlots;
return MathHelper.floor(f * 14.0F) + (i > 0 ? 1 : 0);
}
public static List<Pair<Ingredient, MutableInt>> condenseIngredients(NonNullList<Ingredient> recipeIngredients) {
List<Pair<Ingredient, MutableInt>> actualIngredients = new ArrayList<>();
Ingredients: for (Ingredient igd : recipeIngredients) {

View File

@ -0,0 +1,34 @@
package com.simibubi.create.modules.contraptions.components.contraptions;
import java.util.function.Supplier;
import com.simibubi.create.foundation.packet.SimplePacketBase;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.network.NetworkEvent.Context;
public class CancelPlayerFallPacket extends SimplePacketBase {
public CancelPlayerFallPacket() {
}
public CancelPlayerFallPacket(PacketBuffer buffer) {
}
@Override
public void write(PacketBuffer buffer) {
}
@Override
public void handle(Supplier<Context> context) {
context.get().enqueueWork(() -> {
ServerPlayerEntity sender = context.get().getSender();
sender.fall(sender.fallDistance, 1.0F);
sender.fallDistance = 0;
sender.onGround = true;
});
context.get().setPacketHandled(true);
}
}

View File

@ -8,6 +8,7 @@ import com.simibubi.create.modules.contraptions.components.actors.BlockBreakingM
import net.minecraft.block.BlockState;
import net.minecraft.block.material.PushReaction;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.MoverType;
@ -23,10 +24,14 @@ import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.template.Template.BlockInfo;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.DistExecutor;
public class ContraptionCollider {
static Map<Object, AxisAlignedBB> renderedBBs = new HashMap<>();
public static boolean wasClientPlayerGrounded;
public static void collideEntities(ContraptionEntity contraptionEntity) {
if (Contraption.isFrozen())
@ -71,6 +76,7 @@ public class ContraptionCollider {
entity.fall(entity.fallDistance, 1);
entity.fallDistance = 0;
entity.onGround = true;
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> checkForClientPlayerCollision(entity));
}
if (entity instanceof PlayerEntity && !world.isRemote)
@ -82,6 +88,13 @@ public class ContraptionCollider {
}
@OnlyIn(Dist.CLIENT)
private static void checkForClientPlayerCollision(Entity entity) {
if (entity != Minecraft.getInstance().player)
return;
wasClientPlayerGrounded = true;
}
public static void pushEntityOutOfShape(Entity entity, VoxelShape voxelShape, Vec3d positionOffset,
Vec3d shapeMotion) {
AxisAlignedBB entityBB = entity.getBoundingBox().offset(positionOffset);

View File

@ -2,12 +2,15 @@ package com.simibubi.create.modules.contraptions.components.contraptions.piston;
import java.util.List;
import com.simibubi.create.AllPackets;
import com.simibubi.create.foundation.behaviour.ValueBoxTransform;
import com.simibubi.create.foundation.behaviour.base.TileEntityBehaviour;
import com.simibubi.create.foundation.behaviour.scrollvalue.ScrollOptionBehaviour;
import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.foundation.utility.ServerSpeedProvider;
import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
import com.simibubi.create.modules.contraptions.components.contraptions.CancelPlayerFallPacket;
import com.simibubi.create.modules.contraptions.components.contraptions.ContraptionCollider;
import com.simibubi.create.modules.contraptions.components.contraptions.ContraptionEntity;
import com.simibubi.create.modules.contraptions.components.contraptions.IControlContraption;
@ -202,12 +205,20 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity impleme
protected abstract ValueBoxTransform getMovementModeSlot();
protected abstract void visitNewPosition();
protected abstract Vec3d toMotionVector(float speed);
protected abstract Vec3d toPosition(float offset);
protected void visitNewPosition() {
if (!world.isRemote)
return;
if (!ContraptionCollider.wasClientPlayerGrounded)
return;
// Send falldamage-cancel for the colliding player
ContraptionCollider.wasClientPlayerGrounded = false;
AllPackets.channel.sendToServer(new CancelPlayerFallPacket());
}
protected void tryDisassemble() {
if (removed) {
disassemble();

View File

@ -3,7 +3,6 @@ package com.simibubi.create.modules.contraptions.components.contraptions.piston;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllTileEntities;
import com.simibubi.create.foundation.behaviour.ValueBoxTransform;
import com.simibubi.create.foundation.utility.Debug;
import com.simibubi.create.foundation.utility.ServerSpeedProvider;
import com.simibubi.create.modules.contraptions.base.IRotate;
import com.simibubi.create.modules.contraptions.components.contraptions.ContraptionCollider;

View File

@ -121,6 +121,7 @@ public class PulleyTileEntity extends LinearActuatorTileEntity {
@Override
protected void visitNewPosition() {
super.visitNewPosition();
if (world.isRemote)
return;
if (movedContraption != null)

View File

@ -2,6 +2,7 @@ package com.simibubi.create.modules.contraptions.processing;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.foundation.block.IWithTileEntity;
import com.simibubi.create.foundation.item.ItemHelper;
import com.simibubi.create.foundation.utility.AllShapes;
import net.minecraft.block.Block;
@ -40,12 +41,12 @@ public class BasinBlock extends Block implements IWithTileEntity<BasinTileEntity
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return new BasinTileEntity();
}
@Override
public PushReaction getPushReaction(BlockState state) {
return PushReaction.BLOCK;
}
@Override
public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
BlockRayTraceResult hit) {
@ -57,11 +58,11 @@ public class BasinBlock extends Block implements IWithTileEntity<BasinTileEntity
BasinTileEntity te = (BasinTileEntity) worldIn.getTileEntity(pos);
IItemHandlerModifiable inv = te.inventory.orElse(new ItemStackHandler(1));
for (int slot = 0; slot < inv.getSlots(); slot++) {
player.inventory.placeItemBackInInventory(worldIn, inv.getStackInSlot(slot));
inv.setStackInSlot(slot, ItemStack.EMPTY);
player.inventory.placeItemBackInInventory(worldIn, inv.getStackInSlot(slot));
inv.setStackInSlot(slot, ItemStack.EMPTY);
}
te.onEmptied();
return true;
}
@ -78,12 +79,12 @@ public class BasinBlock extends Block implements IWithTileEntity<BasinTileEntity
BasinTileEntity te = (BasinTileEntity) worldIn.getTileEntity(entityIn.getPosition());
ItemEntity itemEntity = (ItemEntity) entityIn;
ItemStack insertItem = ItemHandlerHelper.insertItem(te.inputInventory, itemEntity.getItem().copy(), false);
if (insertItem.isEmpty()) {
itemEntity.remove();
return;
}
itemEntity.setItem(insertItem);
}
@ -92,7 +93,7 @@ public class BasinBlock extends Block implements IWithTileEntity<BasinTileEntity
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return AllShapes.BASIN_BLOCK_SHAPE;
}
@Override
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (worldIn.getTileEntity(pos) == null)
@ -101,8 +102,7 @@ public class BasinBlock extends Block implements IWithTileEntity<BasinTileEntity
BasinTileEntity te = (BasinTileEntity) worldIn.getTileEntity(pos);
IItemHandlerModifiable inv = te.inventory.orElse(new ItemStackHandler(1));
for (int slot = 0; slot < inv.getSlots(); slot++) {
InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(),
inv.getStackInSlot(slot));
InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), inv.getStackInSlot(slot));
}
if (state.hasTileEntity() && state.getBlock() != newState.getBlock()) {
@ -116,4 +116,19 @@ public class BasinBlock extends Block implements IWithTileEntity<BasinTileEntity
return false;
}
@Override
public boolean hasComparatorInputOverride(BlockState state) {
return true;
}
@Override
public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) {
TileEntity te = worldIn.getTileEntity(pos);
if (te instanceof BasinTileEntity) {
BasinTileEntity basinTileEntity = (BasinTileEntity) te;
return ItemHelper.calcRedstoneFromInventory(basinTileEntity.inputInventory);
}
return 0;
}
}

View File

@ -20,6 +20,7 @@ import net.minecraft.util.Direction.Axis;
import net.minecraft.util.Direction.AxisDirection;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
@ -157,4 +158,19 @@ public class GaugeBlock extends DirectionalAxisKineticBlock {
return GAUGE.get(state.get(FACING), state.get(AXIS_ALONG_FIRST_COORDINATE));
}
@Override
public boolean hasComparatorInputOverride(BlockState state) {
return true;
}
@Override
public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) {
TileEntity te = worldIn.getTileEntity(pos);
if (te instanceof GaugeTileEntity) {
GaugeTileEntity gaugeTileEntity = (GaugeTileEntity) te;
return MathHelper.ceil(MathHelper.clamp(gaugeTileEntity.dialTarget * 14, 0, 15));
}
return 0;
}
}

View File

@ -37,6 +37,8 @@ public class SpeedGaugeTileEntity extends GaugeTileEntity {
} else {
dialTarget = MathHelper.lerp((speed - fast) / (max - fast), .75f, 1.125f);
}
markDirty();
}
}

View File

@ -33,21 +33,24 @@ public class StressGaugeTileEntity extends GaugeTileEntity {
}
sendData();
markDirty();
}
@Override
public void onSpeedChanged(float prevSpeed) {
super.onSpeedChanged(prevSpeed);
if (getSpeed() == 0)
if (getSpeed() == 0) {
dialTarget = 0;
else
updateStressFromNetwork(capacity, stress);
markDirty();
return;
}
updateStressFromNetwork(capacity, stress);
}
public float getNetworkStress() {
return stress;
}
public float getNetworkCapacity() {
return capacity;
}

View File

@ -2,6 +2,7 @@ package com.simibubi.create.modules.logistics.block.inventories;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.foundation.block.ProperDirectionalBlock;
import com.simibubi.create.foundation.item.ItemHelper;
import com.simibubi.create.foundation.utility.AllShapes;
import net.minecraft.block.Block;
@ -160,4 +161,19 @@ public class FlexcrateBlock extends ProperDirectionalBlock {
}
@Override
public boolean hasComparatorInputOverride(BlockState state) {
return true;
}
@Override
public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) {
TileEntity te = worldIn.getTileEntity(pos);
if (te instanceof FlexcrateTileEntity) {
FlexcrateTileEntity flexcrateTileEntity = (FlexcrateTileEntity) te;
return ItemHelper.calcRedstoneFromInventory(flexcrateTileEntity.inventory);
}
return 0;
}
}

View File

@ -113,7 +113,7 @@
"block.create.flywheel": "Flywheel",
"block.create.furnace_engine": "Furnace Engine",
"block.create.speed_gauge": "Speedometer",
"block.create.stress_gauge": "Stress Gauge",
"block.create.stress_gauge": "Stressometer",
"block.create.cart_assembler": "Cart Assembler",
"block.create.analog_lever": "Analog Lever",
"block.create.rotation_speed_controller": "Rotation Speed Controller",
@ -887,7 +887,7 @@
"block.create.mechanical_mixer.tooltip.behaviour3": "Starts to _compact_ _items_ in the basin whenever all necessary ingredients are present.",
"block.create.basin.tooltip": "BASIN",
"block.create.basin.tooltip.summary": "A handy _item_ _container_ used in processing with the _Mechanical_ _Mixer_ and the _Mechanical_ _Press_.",
"block.create.basin.tooltip.summary": "A handy _item_ _container_ used in processing with the _Mechanical_ _Mixer_ and the _Mechanical_ _Press_. Supports _Redstone_ _Comparators_.",
"block.create.mechanical_mixer.tooltip": "MECHANICAL MIXER",
"block.create.mechanical_mixer.tooltip.summary": "A kinetic whisk for applying any shapeless crafting recipes to items beneath it. Requires constant _Rotational_ _Force_ and a _Basin_ placed below (with a gap in between).",
@ -1034,7 +1034,7 @@
"block.create.contact.tooltip.behaviour2": "Triggers all stationary Contacts it passes.",
"block.create.flexcrate.tooltip": "ADJUSTABLE CRATE",
"block.create.flexcrate.tooltip.summary": "This _Storage_ _Container_ allows Manual control over its capacity. It can hold up to _16_ _Stacks_ of any Item.",
"block.create.flexcrate.tooltip.summary": "This _Storage_ _Container_ allows Manual control over its capacity. It can hold up to _16_ _Stacks_ of any Item. Supports _Redstone_ _Comparators_.",
"block.create.flexcrate.tooltip.control1": "When R-Clicked",
"block.create.flexcrate.tooltip.action1": "Opens the _Interface_.",
@ -1128,12 +1128,12 @@
"block.create.redstone_latch.tooltip.summary": "A lever that can be controlled by _Redstone_ _Signals_. A signal on the _back_ _enables_ it, a signal from the _side_ _will_ _reset_ it.",
"block.create.speed_gauge.tooltip": "SPEEDOMETER",
"block.create.speed_gauge.tooltip.summary": "Measures and displays the _rotational_ _speed_ of attached kinetic components.",
"block.create.speed_gauge.tooltip.summary": "Measures and displays the _rotational_ _speed_ of attached kinetic components. Supports _Redstone_ _Comparators_.",
"block.create.speed_gauge.tooltip.condition1": "When Rotated",
"block.create.speed_gauge.tooltip.behaviour1": "Indicates a color corresponding to the level of speed. _Green_ indicates Slow, _Blue_ Moderate and _Purple_ Fast rotation. Some mechanical components require a sufficient level of speed to work properly.",
"block.create.stress_gauge.tooltip": "STRESS GAUGE",
"block.create.stress_gauge.tooltip.summary": "Measures and displays the _overall_ _stress_ of the attached kinetic network.",
"block.create.stress_gauge.tooltip": "STRESSOMETER",
"block.create.stress_gauge.tooltip.summary": "Measures and displays the _overall_ _stress_ of the attached kinetic network. Supports _Redstone_ _Comparators_.",
"block.create.stress_gauge.tooltip.condition1": "When Rotated",
"block.create.stress_gauge.tooltip.behaviour1": "Indicates a color corresponding to the level of stress. _Over-stressed_ _networks_ will cease to move. Stress can be relieved by adding more _rotational_ _sources_ to the network.",