From 4eaa0773900c1200ec30049d270fe6d7ef3909e5 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Tue, 17 Mar 2020 14:25:40 +0100 Subject: [PATCH] Playtest Issues, Part IV - Added null-safety in in-world item processing handlers - Fixed basin-based components not resetting when their speed reaches 0 - Fan-based recipes now scale processing time based on stacksize of the input - Belts now automatically search for attachments on load - Removed duplicate recipe --- .../components/fan/AirCurrent.java | 91 ++++++++++--------- .../press/MechanicalPressTileEntity.java | 3 + .../processing/BasinOperatingTileEntity.java | 17 ++-- .../relays/belt/AllBeltAttachments.java | 4 +- .../modules/logistics/InWorldProcessing.java | 49 ++++++---- .../contraptions/speed_controller.json | 28 ------ 6 files changed, 94 insertions(+), 98 deletions(-) delete mode 100644 src/main/resources/data/create/recipes/crafting_shaped/contraptions/speed_controller.json diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/fan/AirCurrent.java b/src/main/java/com/simibubi/create/modules/contraptions/components/fan/AirCurrent.java index 3f6b2651b..89fb3a6ab 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/fan/AirCurrent.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/fan/AirCurrent.java @@ -38,10 +38,10 @@ import net.minecraftforge.common.Tags; public class AirCurrent { - private static DamageSource damageSourceFire = new DamageSource("create.fan_fire").setDifficultyScaled() - .setFireDamage(); - private static DamageSource damageSourceLava = new DamageSource("create.fan_lava").setDifficultyScaled() - .setFireDamage(); + private static DamageSource damageSourceFire = + new DamageSource("create.fan_fire").setDifficultyScaled().setFireDamage(); + private static DamageSource damageSourceLava = + new DamageSource("create.fan_lava").setDifficultyScaled().setFireDamage(); public final EncasedFanTileEntity source; public AxisAlignedBB bounds = new AxisAlignedBB(0, 0, 0, 0, 0, 0); @@ -84,12 +84,12 @@ public class AirCurrent { Vec3d previousMotion = entity.getMotion(); float maxAcceleration = 5; - double xIn = MathHelper.clamp(flow.getX() * acceleration - previousMotion.x, -maxAcceleration, - maxAcceleration); - double yIn = MathHelper.clamp(flow.getY() * acceleration - previousMotion.y, -maxAcceleration, - maxAcceleration); - double zIn = MathHelper.clamp(flow.getZ() * acceleration - previousMotion.z, -maxAcceleration, - maxAcceleration); + double xIn = + MathHelper.clamp(flow.getX() * acceleration - previousMotion.x, -maxAcceleration, maxAcceleration); + double yIn = + MathHelper.clamp(flow.getY() * acceleration - previousMotion.y, -maxAcceleration, maxAcceleration); + double zIn = + MathHelper.clamp(flow.getZ() * acceleration - previousMotion.z, -maxAcceleration, maxAcceleration); entity.setMotion(previousMotion.add(new Vec3d(xIn, yIn, zIn).scale(1 / 8f))); entity.fallDistance = 0; @@ -99,29 +99,36 @@ public class AirCurrent { entityDistance -= .5f; InWorldProcessing.Type processingType = getSegmentAt((float) entityDistance); - if (entity instanceof ItemEntity) { - InWorldProcessing.spawnParticlesForProcessing(world, entity.getPositionVec(), processingType); - if (InWorldProcessing.canProcess(((ItemEntity) entity), processingType)) - InWorldProcessing.applyProcessing((ItemEntity) entity, processingType); + if (processingType != null) { + if (entity instanceof ItemEntity) { + InWorldProcessing.spawnParticlesForProcessing(world, entity.getPositionVec(), processingType); + if (InWorldProcessing.canProcess(((ItemEntity) entity), processingType)) + InWorldProcessing.applyProcessing((ItemEntity) entity, processingType); - } else { - if (processingType == InWorldProcessing.Type.SMOKING) { - entity.setFire(2); - entity.attackEntityFrom(damageSourceFire, 2); - } - if (processingType == InWorldProcessing.Type.BLASTING) { - entity.setFire(10); - entity.attackEntityFrom(damageSourceLava, 4); - } - if (processingType == InWorldProcessing.Type.SPLASHING) { - if (entity.isBurning()) { + } else { + switch (processingType) { + case BLASTING: + entity.setFire(10); + entity.attackEntityFrom(damageSourceLava, 4); + break; + case SMOKING: + entity.setFire(2); + entity.attackEntityFrom(damageSourceFire, 2); + break; + case SPLASHING: + if (!entity.isBurning()) + break; entity.extinguish(); world.playSound(null, entity.getPosition(), SoundEvents.ENTITY_GENERIC_EXTINGUISH_FIRE, SoundCategory.NEUTRAL, 0.7F, 1.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.4F); + break; + default: + break; } } } + } tickBelts(); @@ -169,11 +176,11 @@ public class AirCurrent { } for (Vec3d offset : offsets) { - Vec3d rayStart = VecHelper.getCenterOf(currentPos).subtract(directionVec.scale(.5f + 1 / 32f)) - .add(offset); + Vec3d rayStart = + VecHelper.getCenterOf(currentPos).subtract(directionVec.scale(.5f + 1 / 32f)).add(offset); Vec3d rayEnd = rayStart.add(directionVec.scale(1 + 1 / 32f)); - BlockRayTraceResult blockraytraceresult = world.rayTraceBlocks(rayStart, rayEnd, currentPos, voxelshape, - state); + BlockRayTraceResult blockraytraceresult = + world.rayTraceBlocks(rayStart, rayEnd, currentPos, voxelshape, state); if (blockraytraceresult == null) continue Outer; @@ -240,20 +247,20 @@ public class AirCurrent { affectedBelts.clear(); for (int i = 0; i < maxDistance + 1; i++) { Type type = getSegmentAt(i); - if (type != null) { - BlockPos pos = start.offset(direction, i); - TileEntity te = world.getTileEntity(pos); - if (te != null && (te instanceof BeltTileEntity)) - affectedBelts.add(Pair.of((BeltTileEntity) te, type)); - if (direction.getAxis().isVertical()) - continue; - - pos = pos.down(); - te = world.getTileEntity(pos); - if (te == null || !(te instanceof BeltTileEntity)) - continue; + if (type == null) + continue; + BlockPos pos = start.offset(direction, i); + TileEntity te = world.getTileEntity(pos); + if (te != null && (te instanceof BeltTileEntity)) affectedBelts.add(Pair.of((BeltTileEntity) te, type)); - } + if (direction.getAxis().isVertical()) + continue; + + pos = pos.down(); + te = world.getTileEntity(pos); + if (te == null || !(te instanceof BeltTileEntity)) + continue; + affectedBelts.add(Pair.of((BeltTileEntity) te, type)); } } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/press/MechanicalPressTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/components/press/MechanicalPressTileEntity.java index d0ef8f9b3..fd3c75b67 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/press/MechanicalPressTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/press/MechanicalPressTileEntity.java @@ -315,6 +315,9 @@ public class MechanicalPressTileEntity extends BasinOperatingTileEntity { protected void basinRemoved() { pressedItems.clear(); super.basinRemoved(); + running = false; + runningTicks = 0; + sendData(); } } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/processing/BasinOperatingTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/processing/BasinOperatingTileEntity.java index 170a923da..3e7307b7c 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/processing/BasinOperatingTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/processing/BasinOperatingTileEntity.java @@ -38,6 +38,8 @@ public abstract class BasinOperatingTileEntity extends KineticTileEntity { @Override public void onSpeedChanged(float prevSpeed) { super.onSpeedChanged(prevSpeed); + if (getSpeed() == 0) + basinRemoved = true; checkBasin = true; } @@ -66,6 +68,8 @@ public abstract class BasinOperatingTileEntity extends KineticTileEntity { if (!isSpeedRequirementFulfilled()) return; + if (getSpeed() == 0) + return; if (!isCheckingBasin()) return; if (!checkBasin) @@ -83,11 +87,6 @@ public abstract class BasinOperatingTileEntity extends KineticTileEntity { return; gatherInputs(); -// if (matchBasinRecipe(lastRecipe)) { -// startProcessingBasin(); -// sendData(); -// return; -// } List> recipes = getMatchingRecipes(); if (recipes.isEmpty()) return; @@ -96,7 +95,7 @@ public abstract class BasinOperatingTileEntity extends KineticTileEntity { startProcessingBasin(); sendData(); } - + protected boolean isCheckingBasin() { return true; } @@ -121,7 +120,7 @@ public abstract class BasinOperatingTileEntity extends KineticTileEntity { IItemHandlerModifiable inputs = inv.getInputHandler(); IItemHandlerModifiable outputs = inv.getOutputHandler(); List catalysts = new ArrayList<>(); - + int buckets = 0; Ingredients: for (Ingredient ingredient : lastRecipe.getIngredients()) { for (int slot = 0; slot < inputs.getSlots(); slot++) { @@ -130,7 +129,7 @@ public abstract class BasinOperatingTileEntity extends KineticTileEntity { ItemStack extracted = inputs.extractItem(slot, 1, false); if (extracted.getItem() instanceof BucketItem) buckets++; - + if ((lastRecipe instanceof ProcessingRecipe)) { ProcessingRecipe pr = (ProcessingRecipe) lastRecipe; if (pr.getRollableIngredients().get(slot).remains()) @@ -150,7 +149,7 @@ public abstract class BasinOperatingTileEntity extends KineticTileEntity { // Continue mixing gatherInputs(); if (matchBasinRecipe(lastRecipe)) { - continueWithPreviousRecipe(); + continueWithPreviousRecipe(); sendData(); } } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/AllBeltAttachments.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/AllBeltAttachments.java index f6554b17f..b426d8fc1 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/AllBeltAttachments.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/AllBeltAttachments.java @@ -161,8 +161,10 @@ public enum AllBeltAttachments { public void readAndSearch(CompoundNBT nbt, BeltTileEntity belt) { attachments.clear(); - if (!nbt.contains("HasAttachments")) + if (!nbt.contains("HasAttachments")) { + findAttachments(belt); return; + } if (nbt.contains("AttachmentData")) { ListNBT list = (ListNBT) nbt.get("AttachmentData"); for (INBT data : list) { diff --git a/src/main/java/com/simibubi/create/modules/logistics/InWorldProcessing.java b/src/main/java/com/simibubi/create/modules/logistics/InWorldProcessing.java index 6d0994a67..498957d09 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/InWorldProcessing.java +++ b/src/main/java/com/simibubi/create/modules/logistics/InWorldProcessing.java @@ -51,9 +51,7 @@ public class InWorldProcessing { public static SplashingInv splashingInv = new SplashingInv(); public enum Type { - SMOKING, - BLASTING, - SPLASHING + SMOKING, BLASTING, SPLASHING ; @@ -137,7 +135,10 @@ public class InWorldProcessing { Type type) { if (transported.processedBy != type) { transported.processedBy = type; - transported.processingTime = AllConfigs.SERVER.kinetics.inWorldProcessingTime.get() + 1; + int timeModifierForStackSize = ((transported.stack.getCount() - 1) / 16) + 1; + int processingTime = + (int) (AllConfigs.SERVER.kinetics.inWorldProcessingTime.get() * timeModifierForStackSize) + 1; + transported.processingTime = processingTime; if (!canProcess(transported.stack, type, belt.getWorld())) transported.processingTime = -1; return null; @@ -215,7 +216,10 @@ public class InWorldProcessing { if (!processing.contains("Type") || Type.valueOf(processing.getString("Type")) != type) { processing.putString("Type", type.name()); - processing.putInt("Time", AllConfigs.SERVER.kinetics.inWorldProcessingTime.get() + 1); + int timeModifierForStackSize = ((entity.getItem().getCount() - 1) / 16) + 1; + int processingTime = + (int) (AllConfigs.SERVER.kinetics.inWorldProcessingTime.get() * timeModifierForStackSize) + 1; + processing.putInt("Time", processingTime); } int value = processing.getInt("Time") - 1; @@ -273,19 +277,28 @@ public class InWorldProcessing { } public static void spawnParticlesForProcessing(World world, Vec3d vec, Type type) { - if (world.rand.nextInt(4) == 0 && world.isRemote) { - if (type == Type.BLASTING) - world.addParticle(ParticleTypes.LARGE_SMOKE, vec.x, vec.y + .25f, vec.z, 0, 1 / 16f, 0); - if (type == Type.SMOKING) - world.addParticle(ParticleTypes.POOF, vec.x, vec.y + .25f, vec.z, 0, 1 / 16f, 0); - if (type == Type.SPLASHING) { - Vec3d color = ColorHelper.getRGB(0x0055FF); - world.addParticle(new RedstoneParticleData((float) color.x, (float) color.y, (float) color.z, 1), - vec.x + (world.rand.nextFloat() - .5f) * .5f, vec.y + .5f, - vec.z + (world.rand.nextFloat() - .5f) * .5f, 0, 1 / 8f, 0); - world.addParticle(ParticleTypes.SPIT, vec.x + (world.rand.nextFloat() - .5f) * .5f, vec.y + .5f, - vec.z + (world.rand.nextFloat() - .5f) * .5f, 0, 1 / 8f, 0); - } + if (!world.isRemote) + return; + if (world.rand.nextInt(4) != 0) + return; + + switch (type) { + case BLASTING: + world.addParticle(ParticleTypes.LARGE_SMOKE, vec.x, vec.y + .25f, vec.z, 0, 1 / 16f, 0); + break; + case SMOKING: + world.addParticle(ParticleTypes.POOF, vec.x, vec.y + .25f, vec.z, 0, 1 / 16f, 0); + break; + case SPLASHING: + Vec3d color = ColorHelper.getRGB(0x0055FF); + world.addParticle(new RedstoneParticleData((float) color.x, (float) color.y, (float) color.z, 1), + vec.x + (world.rand.nextFloat() - .5f) * .5f, vec.y + .5f, + vec.z + (world.rand.nextFloat() - .5f) * .5f, 0, 1 / 8f, 0); + world.addParticle(ParticleTypes.SPIT, vec.x + (world.rand.nextFloat() - .5f) * .5f, vec.y + .5f, + vec.z + (world.rand.nextFloat() - .5f) * .5f, 0, 1 / 8f, 0); + break; + default: + break; } } diff --git a/src/main/resources/data/create/recipes/crafting_shaped/contraptions/speed_controller.json b/src/main/resources/data/create/recipes/crafting_shaped/contraptions/speed_controller.json deleted file mode 100644 index d375e21f8..000000000 --- a/src/main/resources/data/create/recipes/crafting_shaped/contraptions/speed_controller.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "type": "crafting_shaped", - "pattern": [ - " B ", - "SCS" - ], - "key": { - "S": { - "item": "create:shaft" - }, - "B": { - "item": "create:integrated_circuit" - }, - "C": { - "item": "create:brass_casing" - } - }, - "result": { - "item": "create:rotation_speed_controller", - "count": 1 - }, - "conditions": [ - { - "type": "create:module", - "module": "contraptions" - } - ] -} \ No newline at end of file