Skip to content

Commit

Permalink
⛽ Creative pump
Browse files Browse the repository at this point in the history
  • Loading branch information
petrolpark committed Oct 4, 2024
1 parent b39e50c commit 6d74d18
Show file tree
Hide file tree
Showing 29 changed files with 365 additions and 50 deletions.
36 changes: 36 additions & 0 deletions src/main/java/com/petrolpark/destroy/block/CreativePumpBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.petrolpark.destroy.block;

import com.petrolpark.destroy.block.entity.DestroyBlockEntityTypes;
import com.petrolpark.destroy.block.shape.DestroyShapes;
import com.simibubi.create.content.fluids.pump.PumpBlock;
import com.simibubi.create.content.fluids.pump.PumpBlockEntity;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;

public class CreativePumpBlock extends PumpBlock {

public CreativePumpBlock(Properties properties) {
super(properties);
};

@Override
public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return DestroyShapes.CREATIVE_PUMP.get(state.getValue(FACING).getAxis());
};

@Override
public BlockEntityType<? extends PumpBlockEntity> getBlockEntityType() {
return DestroyBlockEntityTypes.CREATIVE_PUMP.get();
};

@Override
public boolean isSmallCog() {
return false;
};

};
13 changes: 13 additions & 0 deletions src/main/java/com/petrolpark/destroy/block/DestroyBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.Rarity;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
Expand Down Expand Up @@ -146,6 +147,18 @@ public class DestroyBlocks {
.transform(customItemModel())
.register();

public static final BlockEntry<CreativePumpBlock> CREATIVE_PUMP = REGISTRATE.block("creative_pump", CreativePumpBlock::new)
.initialProperties(AllBlocks.MECHANICAL_PUMP)
.properties(p -> p
.mapColor(MapColor.COLOR_PURPLE)
.forceSolidOn()
).transform(TagGen.pickaxeOnly())
.item()
.properties(p -> p
.rarity(Rarity.EPIC)
).build()
.register();

public static final BlockEntry<CustomExplosiveMixBlock> CUSTOM_EXPLOSIVE_MIX = REGISTRATE.block("custom_explosive_mix", CustomExplosiveMixBlock::new)
.initialProperties(() -> Blocks.TNT)
.properties(p -> p
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ public void onTimerChange() {
if (timer <= 0) {
tank.allowExtraction();
tank.allowInsertion();
} else {
tank.forbidExtraction();
tank.forbidInsertion();
};
int progress;
if (timer < 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.petrolpark.destroy.block.entity;

import java.util.List;

import com.google.common.collect.ImmutableList;
import com.petrolpark.destroy.block.CreativePumpBlock;
import com.simibubi.create.content.fluids.pump.PumpBlockEntity;
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
import com.simibubi.create.foundation.blockEntity.behaviour.ValueBoxTransform;
import com.simibubi.create.foundation.blockEntity.behaviour.ValueSettingsBoard;
import com.simibubi.create.foundation.blockEntity.behaviour.ValueSettingsFormatter;
import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.ScrollValueBehaviour;
import com.simibubi.create.foundation.utility.VecHelper;
import com.simibubi.create.infrastructure.config.AllConfigs;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;

public class CreativePumpBlockEntity extends PumpBlockEntity {

public ScrollValueBehaviour pumpSpeedBehaviour;
protected int simulatedSpeed = 16; // Can't use KineticBlockEntity speed because this gets set to 0 if there is no source

public CreativePumpBlockEntity(BlockEntityType<?> typeIn, BlockPos pos, BlockState state) {
super(typeIn, pos, state);
};

@Override
public void addBehaviours(List<BlockEntityBehaviour> behaviours) {
super.addBehaviours(behaviours);
pumpSpeedBehaviour = new ScrollValueBehaviour(Component.translatable("block.destroy.creative_pump.speed"), this, new CreativePumpValueSlot()) {
@Override
public ValueSettingsBoard createBoard(Player player, BlockHitResult hitResult) {
return new ValueSettingsBoard(label, max, 16, ImmutableList.of(Component.translatable("block.destroy.creative_pump.speed")), new ValueSettingsFormatter(ValueSettings::format));
};
}
.between(0, AllConfigs.server().kinetics.maxRotationSpeed.get())
.withCallback(i -> {
simulatedSpeed = i;
updatePressureChange();
});
pumpSpeedBehaviour.setValue(simulatedSpeed);
behaviours.add(pumpSpeedBehaviour);
};

@Override
public float getSpeed() {
return simulatedSpeed;
};

@Override
protected void read(CompoundTag compound, boolean clientPacket) {
super.read(compound, clientPacket);
simulatedSpeed = compound.getInt("SimulatedSpeed");
pumpSpeedBehaviour.setValue(simulatedSpeed);
};

@Override
protected void write(CompoundTag compound, boolean clientPacket) {
super.write(compound, clientPacket);
compound.putInt("SimulatedSpeed", simulatedSpeed);
};

public class CreativePumpValueSlot extends ValueBoxTransform.Sided {

@Override
protected boolean isSideActive(BlockState state, Direction direction) {
return state.getValue(CreativePumpBlock.FACING).getAxis() != direction.getAxis();
};

@Override
protected Vec3 getSouthLocation() {
return VecHelper.voxelSpace(8d, 8d, 12.5d);
};

};

};
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public class DestroyBlockEntityTypes {
.renderer(() -> CoolerRenderer::new)
.register();

public static final BlockEntityEntry<CreativePumpBlockEntity> CREATIVE_PUMP = REGISTRATE
.blockEntity("creative_pump", CreativePumpBlockEntity::new)
.validBlocks(DestroyBlocks.CREATIVE_PUMP)
.register();

public static final BlockEntityEntry<CustomExplosiveMixBlockEntity> CUSTOM_EXPLOSIVE_MIX = REGISTRATE
.blockEntity("custom_explosive_mix", CustomExplosiveMixBlockEntity::new)
.validBlocks(DestroyBlocks.CUSTOM_EXPLOSIVE_MIX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ public void updateDisplayType(BlockPos neighborPos) {
};
boolean nextToAir = getLevel().getBlockState(neighborPos).isAir(); // It thinks getLevel() might be null (it's not)

DisplayType oldDisplayType = getDisplayType();
if (nextToPipe) {
setDisplayType(DisplayType.PIPE);
} else if (!nextToAir) {
Expand Down Expand Up @@ -478,8 +479,10 @@ public void updateDisplayType(BlockPos neighborPos) {
};
};

redstoneMonitor.update();
invalidateRenderBoundingBox();
if (getDisplayType() != oldDisplayType) {
redstoneMonitor.update();
invalidateRenderBoundingBox();
};
};

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public int getStrength() {
};

public void update() {
getWorld().blockUpdated(getPos(), getWorld().getBlockState(getPos()).getBlock());
getWorld().updateNeighborsAt(getPos(), blockEntity.getBlockState().getBlock());
//TODO update adjacent positions?
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.PoseStack;
import com.petrolpark.destroy.Destroy;
import com.petrolpark.destroy.block.AgingBarrelBlock;
import com.petrolpark.destroy.block.entity.AgingBarrelBlockEntity;
import com.petrolpark.destroy.util.DestroyTags.DestroyItemTags;
import com.simibubi.create.foundation.fluid.FluidRenderer;
Expand Down Expand Up @@ -39,6 +40,8 @@ public AgingBarrelRenderer(BlockEntityRendererProvider.Context context) {
protected void renderSafe(AgingBarrelBlockEntity barrel, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
super.renderSafe(barrel, partialTicks, ms, buffer, light, overlay);

if (!barrel.getBlockState().getValue(AgingBarrelBlock.IS_OPEN)) return;

//render Fluid
float fluidLevel = renderFluid(barrel, partialTicks, ms, buffer, light, overlay);

Expand Down Expand Up @@ -104,7 +107,7 @@ protected float renderFluid(AgingBarrelBlockEntity barrel, float partialTicks, P
TankSegment tank = barrel.getTankToRender();
float units = tank.getTotalUnits(partialTicks);
float maxY = minY + (Mth.clamp(units / barrel.getTank().getCapacity(), 0, 1) * 8 / 12f);
if (units < 1) return minY;
if (units < 1 || tank.getRenderedFluid().isEmpty()) return minY;
FluidRenderer.renderFluidBox(tank.getRenderedFluid(), 2 / 16f, minY, 2 / 16f, 14 / 16f, maxY, 14 / 16f, buffer, ms, light, false);
return maxY;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ public class DestroyShapes {
.add(2, 2, 2, 14, 10, 14)
.add(3, 10, 3, 13, 12, 13)
.add(5, 12, 5, 11, 16, 11)
.forDirectional(Direction.UP);
.forDirectional(Direction.UP),

CREATIVE_PUMP = shape(3, 0, 3, 13, 16, 13)
.forAxis();

public static final VoxelShaper BLOWPIPE = shape(7, 0, 7, 9, 16, 9).forAxis();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@
import com.petrolpark.destroy.client.ponder.scene.TrypolithographyScenes;
import com.petrolpark.destroy.item.DestroyItems;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.Create;
import com.simibubi.create.foundation.ponder.PonderRegistrationHelper;
import com.simibubi.create.foundation.ponder.PonderRegistry;
import com.simibubi.create.foundation.ponder.PonderStoryBoardEntry;
import com.simibubi.create.infrastructure.ponder.AllPonderTags;
import com.simibubi.create.infrastructure.ponder.scenes.fluid.PumpScenes;

import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;

public class DestroyPonderIndex {

public static final PonderRegistrationHelper CREATE_HELPER = new PonderRegistrationHelper(Create.ID);
public static final PonderRegistrationHelper HELPER = new PonderRegistrationHelper(Destroy.MOD_ID);

public static void register() {
Expand Down Expand Up @@ -75,6 +78,10 @@ public static void register() {
.addStoryBoard("processing/cooler", ProcessingScenes::cooler)
.addStoryBoard("vat/temperature", ChemistryScenes::vatTemperature, DestroyPonderTags.CHEMISTRY);

// Creative Pump
CREATE_HELPER.forComponents(DestroyBlocks.CREATIVE_PUMP)
.addStoryBoard("mechanical_pump/flow", PumpScenes::flow);

// Custom Explosive Mix
HELPER.forComponents(DestroyBlocks.CUSTOM_EXPLOSIVE_MIX)
.addStoryBoard("explosives/custom_explosive_mix", (s, u) -> ExplosivesScenes.filling(s, u, DestroyBlocks.CUSTOM_EXPLOSIVE_MIX::asStack))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static void register() {
.add(DestroyBlocks.CATALYTIC_CONVERTER)
.add(DestroyBlocks.CENTRIFUGE)
.add(DestroyBlocks.COOLER)
.add(DestroyBlocks.CREATIVE_PUMP)
.add(DestroyBlocks.CUSTOM_EXPLOSIVE_MIX)
.add(DestroyBlocks.DYNAMO)
.add(DestroyBlocks.EXTRUSION_DIE)
Expand All @@ -67,6 +68,7 @@ public static void register() {
.add(DestroyBlocks.BUBBLE_CAP)
.add(DestroyBlocks.CATALYTIC_CONVERTER)
.add(DestroyBlocks.CENTRIFUGE)
.add(DestroyBlocks.CREATIVE_PUMP)
.add(DestroyBlocks.PUMPJACK)
.add(DestroyBlocks.SIPHON)
.add(DestroyBlocks.TREE_TAP)
Expand Down Expand Up @@ -103,6 +105,10 @@ public static void register() {
PonderRegistry.TAGS.forTag(AllPonderTags.CONTRAPTION_ACTOR)
.add(DestroyBlocks.EXTRUSION_DIE)
;

PonderRegistry.TAGS.forTag(AllPonderTags.CREATIVE)
.add(DestroyBlocks.CREATIVE_PUMP)
;
};

public static final void refreshVatMaterialsTag() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ public void setPlacedBy(Level level, BlockPos pos, BlockState state, LivingEntit

@Override
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult pHit) {
InteractionResult dyeingResult = onBlockEntityUse(level, pos, be -> be.tryDye(player.getItemInHand(hand), pHit, level, pos, player));
if (dyeingResult != InteractionResult.PASS) return dyeingResult;
InteractionResult result = onBlockEntityUse(level, pos, be -> be.tryDye(player.getItemInHand(hand), pHit, level, pos, player));
if (result != InteractionResult.PASS) return result;
result = super.use(state, level, pos, player, hand, pHit); // Fuse
if (result != InteractionResult.PASS) return result;
if (!level.isClientSide() && player instanceof ServerPlayer serverPlayer) {
withBlockEntityDo(level, pos, be -> NetworkHooks.openScreen(serverPlayer, be, be::writeToBuffer));
return InteractionResult.SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.mojang.blaze3d.vertex.PoseStack;
import com.petrolpark.client.rendering.PetrolparkGuiTexture;
import com.petrolpark.compat.jei.category.PetrolparkRecipeCategory;
import com.petrolpark.destroy.block.DestroyBlocks;
import com.petrolpark.destroy.item.CustomExplosiveMixBlockItem;
import com.petrolpark.destroy.recipe.ObliterationRecipe;
import com.petrolpark.destroy.util.DestroyTags.DestroyItemTags;
import com.simibubi.create.content.processing.recipe.ProcessingOutput;
Expand All @@ -17,8 +19,6 @@
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.registries.ForgeRegistries;

public class ObliterationCategory extends PetrolparkRecipeCategory<ObliterationRecipe> {

Expand All @@ -32,13 +32,9 @@ public void setRecipe(IRecipeLayoutBuilder builder, ObliterationRecipe recipe, I
.setBackground(getRenderedSlot(), -1, -1)
.addIngredients(recipe.getIngredients().get(0));

List<ItemStack> explosives = new ArrayList<>();
ForgeRegistries.ITEMS.tags().getTag(DestroyItemTags.OBLITERATION_EXPLOSIVES.tag).forEach(item -> {
explosives.add(new ItemStack(item));
});
builder.addSlot(RecipeIngredientRole.CATALYST, 77, 26)
.setBackground(getRenderedSlot(), -1, -1)
.addItemStacks(explosives);
.addItemStack(CustomExplosiveMixBlockItem.getExampleItemStack());

ProcessingOutput output = recipe.getRollableResults().get(0);
builder.addSlot(RecipeIngredientRole.OUTPUT, 131, 51)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ public WaterSensitiveSpontaneouslyCombustingItem(Properties properties) {
@Override
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) {
super.inventoryTick(stack, level, entity, slotId, isSelected);
checkForWater(stack, entity, isSelected);
if (checkForWater(stack, entity, isSelected)) stack.setCount(0);
};

@Override
public boolean onEntityItemUpdate(ItemStack stack, ItemEntity entity) {
checkForWater(stack, entity, true);
if (checkForWater(stack, entity, true)) entity.kill();
return super.onEntityItemUpdate(stack, entity);
};

public void checkForWater(ItemStack stack, Entity entity, boolean rainSensitive) {
public boolean checkForWater(ItemStack stack, Entity entity, boolean rainSensitive) {
if (entity.isInWaterOrBubble() || (entity.isInWaterRainOrBubble() && (rainSensitive || (entity instanceof LivingEntity livingEntity && livingEntity.getOffhandItem() == stack)))) {
SmartExplosion.explode(entity.level(), new SmartExplosion(entity.level(), entity, null, null, entity.position(), 2f, 0.7f));
return true;
};
return false;
};
};
Loading

0 comments on commit 6d74d18

Please sign in to comment.