some stuff
This commit is contained in:
@@ -5,6 +5,7 @@ import com.drmangotea.tfmg.base.TFMGCreativeTabs;
|
||||
import com.drmangotea.tfmg.base.TFMGRegistrate;
|
||||
import com.drmangotea.tfmg.content.electricity.base.ElectricNetworkManager;
|
||||
import com.drmangotea.tfmg.content.items.weapons.explosives.thermite_grenades.fire.TFMGColoredFires;
|
||||
import com.drmangotea.tfmg.content.machinery.oil_processing.pumpjack.pumpjack.base.DepositManager;
|
||||
import com.drmangotea.tfmg.datagen.TFMGDatagen;
|
||||
import com.drmangotea.tfmg.base.fluid.TFMGFluidInteractions;
|
||||
import com.drmangotea.tfmg.config.TFMGConfigs;
|
||||
@@ -36,6 +37,7 @@ public class TFMG {
|
||||
|
||||
public static final String MOD_ID = "tfmg";
|
||||
public static final ElectricNetworkManager NETWORK_MANAGER = new ElectricNetworkManager();
|
||||
public static final DepositManager DEPOSITS = new DepositManager();
|
||||
|
||||
public static final Logger LOGGER = LogUtils.getLogger();
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.drmangotea.tfmg;
|
||||
import com.drmangotea.tfmg.content.items.weapons.advanced_potato_cannon.AdvancedPotatoCannonRenderHandler;
|
||||
import com.drmangotea.tfmg.content.items.weapons.flamethrover.FlamethrowerRenderHandler;
|
||||
import com.drmangotea.tfmg.content.items.weapons.quad_potato_cannon.QuadPotatoCannonRenderHandler;
|
||||
import com.drmangotea.tfmg.ponder.TFMGPonderIndex;
|
||||
import com.drmangotea.tfmg.registry.TFMGParticleTypes;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
@@ -14,13 +15,13 @@ public class TFMGClient {
|
||||
|
||||
/**
|
||||
* does not work, too bad!
|
||||
*/
|
||||
*/
|
||||
public static final QuadPotatoCannonRenderHandler QUAD_POTATO_CANNON_RENDER_HANDLER = new QuadPotatoCannonRenderHandler();
|
||||
public static final AdvancedPotatoCannonRenderHandler ADVANCED_POTATO_CANNON_RENDER_HANDLER = new AdvancedPotatoCannonRenderHandler();
|
||||
|
||||
public static final FlamethrowerRenderHandler FLAMETHROWER_RENDER_HANDLER = new FlamethrowerRenderHandler();
|
||||
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
public TFMGClient() {
|
||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
IEventBus forgeEventBus = MinecraftForge.EVENT_BUS;
|
||||
@@ -36,7 +37,7 @@ public class TFMGClient {
|
||||
|
||||
@SubscribeEvent
|
||||
public void setup(final FMLClientSetupEvent event) {
|
||||
// TFMGPonderIndex.register();
|
||||
// TFMGPonderIndex.registerTags();
|
||||
TFMGPonderIndex.register();
|
||||
TFMGPonderIndex.registerTags();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.drmangotea.tfmg.base;
|
||||
import com.drmangotea.tfmg.content.machinery.misc.winding_machine.SpoolItem;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlocks;
|
||||
import com.drmangotea.tfmg.registry.TFMGItems;
|
||||
import com.drmangotea.tfmg.registry.TFMGPaletteStoneTypes;
|
||||
import com.simibubi.create.AllCreativeModeTabs;
|
||||
import com.simibubi.create.content.processing.sequenced.SequencedAssemblyItem;
|
||||
import com.simibubi.create.foundation.data.CreateRegistrate;
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
package com.drmangotea.tfmg.base;
|
||||
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlocks;
|
||||
import com.drmangotea.tfmg.base.fluid.GasFluidType;
|
||||
import com.simibubi.create.content.fluids.VirtualFluid;
|
||||
import com.simibubi.create.foundation.data.CreateRegistrate;
|
||||
import com.tterrag.registrate.util.DataIngredient;
|
||||
import com.tterrag.registrate.util.entry.BlockEntry;
|
||||
import net.minecraft.data.recipes.RecipeCategory;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import com.simibubi.create.foundation.data.VirtualFluidBuilder;
|
||||
import com.tterrag.registrate.builders.FluidBuilder;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.*;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import static com.simibubi.create.foundation.data.BlockStateGen.simpleCubeAll;
|
||||
import static com.simibubi.create.foundation.data.ModelGen.customItemModel;
|
||||
import static com.simibubi.create.foundation.data.TagGen.pickaxeOnly;
|
||||
|
||||
public class TFMGRegistrate extends CreateRegistrate {
|
||||
public static String autoLang(String id) {
|
||||
@@ -31,6 +28,13 @@ public class TFMGRegistrate extends CreateRegistrate {
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public FluidBuilder<VirtualFluid, CreateRegistrate> gasFluid(String name, ResourceLocation still,
|
||||
ResourceLocation flow) {
|
||||
return entry(name, c -> new VirtualFluidBuilder<>(self(), self(), name, c, still, flow,
|
||||
GasFluidType.create(), VirtualFluid::new));
|
||||
}
|
||||
|
||||
protected TFMGRegistrate() {
|
||||
super(TFMG.MOD_ID);
|
||||
}
|
||||
|
||||
@@ -15,14 +15,10 @@ import static net.minecraft.core.Direction.*;
|
||||
|
||||
public class TFMGShapes {
|
||||
public static final VoxelShaper
|
||||
ENGINE_BACK = shape(3, 0, 3, 13, 16, 16)
|
||||
.forDirectional(),
|
||||
ENGINE_BACK_VERTICAL = shape(3, 0, 3, 16, 16, 13)
|
||||
.forDirectional(),
|
||||
ENGINE_VERTICAL = shape(3, 0, 3, 13, 14, 16)
|
||||
.forDirectional(),
|
||||
ENGINE = shape(3, 0, 3, 13, 14, 16)
|
||||
.forDirectional(),
|
||||
ENGINE = shape(0, 0, 0, 16, 7, 16).add(3, 7, 0, 13, 12, 16)
|
||||
.forDirectional(SOUTH),
|
||||
ENGINE_FRONT = shape(0, 0, 1, 16, 7, 16).add(3, 7, 1, 13, 12, 16)
|
||||
.forDirectional(SOUTH),
|
||||
PUMPJACK_HAMMER_PART = shape(0, 2, 0, 16, 14, 16)
|
||||
.forDirectional(),
|
||||
RADIAL_ENGINE = shape(1, 4, 1, 15, 12, 15)
|
||||
@@ -41,6 +37,8 @@ public class TFMGShapes {
|
||||
.forDirectional(),
|
||||
GALVANIC_CELL = shape(5, 10, 5, 11, 16, 16).add(1, 4, 6, 15, 10, 16)
|
||||
.forDirectional(),
|
||||
RESISTOR = shape(6, 0, 3, 10, 4, 13)
|
||||
.forDirectional(),
|
||||
GENERATOR = shape(3, 0, 3, 13, 14, 13).add(0, 4, 0, 16, 10, 16)
|
||||
.forDirectional(),
|
||||
LIGHT_BULB = shape(5, 0, 5, 11, 9, 11)
|
||||
@@ -51,15 +49,23 @@ public class TFMGShapes {
|
||||
.forDirectional(),
|
||||
ALUMINUM_LAMP = shape(3, 0, 3, 13, 2, 13).add(4, 2, 4, 12, 3, 12)
|
||||
.forDirectional(),
|
||||
RESISTOR = shape(3, 0, 3, 13, 16, 13).add(1, 1, 13, 15, 15, 16)
|
||||
POTENTIOMETER = shape(3, 0, 3, 13, 16, 13).add(1, 1, 13, 15, 15, 16)
|
||||
.forDirectional(),
|
||||
WINDING_MACHINE = shape(0, 0, 0, 16, 8, 16).add(0, 8, 4, 10, 12, 12)
|
||||
.forHorizontal(NORTH),
|
||||
RESISTOR_VERTICAL = shape(3, 0, 3, 13, 16, 13)
|
||||
.forDirectional(),
|
||||
BLAST_FURNACE_REINFORCEMENT_WALL = shape(00, 0, 0, 16, 6, 16)
|
||||
BLAST_FURNACE_REINFORCEMENT_WALL = shape(0, 0, 0, 16, 6, 16)
|
||||
.forDirectional(),
|
||||
|
||||
ROTOR = shape(3, 3, 2, 13, 13, 14)
|
||||
.forAxis(),
|
||||
ROTOR = shape(4, 5, 4, 12, 11, 12).add(5, 0, 5, 11, 16, 11)
|
||||
.forDirectional(),
|
||||
STATOR = shape(5, 1, 0, 16, 15.2, 5).add(5, 1, 5, 10, 15.2, 10).add(0, 1, 0, 5, 15.2, 16)
|
||||
.forDirectional(),
|
||||
STATOR_ROTATED = shape(5, 1, 11, 16, 15, 16).add(5, 1, 6, 10, 15, 11).add(0, 1, 0, 5, 15, 16)
|
||||
.forDirectional(),
|
||||
STATOR_VERTICAL = shape(5, 0, 1, 16, 5, 15).add(5, 5, 1, 10, 10, 15).add(0, 0, 1, 5, 16, 15)
|
||||
.forDirectional(),
|
||||
VOLTMETER = shape(0, 0, 2, 16, 3, 14)
|
||||
.forDirectional(),
|
||||
DIAGONAL_CABLE_BLOCK_DOWN = shape(3, 3, 11, 13, 13, 16)
|
||||
@@ -70,6 +76,9 @@ public class TFMGShapes {
|
||||
.add(3, 11, 3, 13, 16, 13)
|
||||
.add(4, 4, 5, 12, 11, 12)
|
||||
.forDirectional(),
|
||||
CASTING_BASIN = shape(0, 0, 0, 16, 8, 16)
|
||||
.add(4, 8, 14, 12, 13, 16)
|
||||
.forHorizontal(NORTH),
|
||||
CABLE_TUBE = shape(6, 0, 6, 10, 16, 10)
|
||||
.forDirectional(),
|
||||
REBAR_PILLAR = shape(3, 0, 3, 13, 16, 13)
|
||||
@@ -95,8 +104,6 @@ public class TFMGShapes {
|
||||
FLARESTACK = shape(3, 0, 3, 13, 14, 14).build(),
|
||||
PUMPJACK_BASE = shape(3, 0, 3, 13, 16, 13).build(),
|
||||
TRAFFIC_LIGHT = shape(3, 0, 3, 13, 16, 13).build(),
|
||||
CASTING_SPOUT = shape(1, 2, 1, 15, 14, 15)
|
||||
.build(),
|
||||
REBAR_FLOOR = shape(0, 4, 0, 16, 12, 16)
|
||||
.build(),
|
||||
SURFACE_SCANNER = shape(2, 0, 2, 14, 14, 14).build(),
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.simibubi.create.foundation.block.render.SpriteShifter;
|
||||
public class TFMGSpriteShifts {
|
||||
|
||||
public static final CTSpriteShiftEntry CAST_IRON_BLOCK = omni("cast_iron_block"), LEAD_BLOCK = omni("lead_block"), STEEL_BLOCK = omni("steel_block");
|
||||
public static final CTSpriteShiftEntry STEEL_FLUID_TANK = getCT(AllCTTypes.RECTANGLE, "steel_fluid_tank"), STEEL_FLUID_TANK_TOP = getCT(AllCTTypes.RECTANGLE, "steel_fluid_tank_top"), STEEL_FLUID_TANK_INNER = getCT(AllCTTypes.RECTANGLE, "steel_fluid_tank_inner");
|
||||
public static final CTSpriteShiftEntry HEAVY_MACHINERY_CASING = omni("heavy_machinery_casing"), ELECTRIC_CASING = omni("electric_casing"), STEEL_CASING = omni("steel_casing"), INDUSTRIAL_ALUMINUM_CASING = omni("industrial_aluminum_casing");
|
||||
public static final CTSpriteShiftEntry CAPACITOR = getCT(AllCTTypes.RECTANGLE, "capacitor_side"), ACCUMULATOR = getCT(AllCTTypes.RECTANGLE, "accumulator_side");
|
||||
public static final CTSpriteShiftEntry STEEL_SCAFFOLD = horizontal("scaffold/steel_scaffold"), ALUMINUM_SCAFFOLD = horizontal("scaffold/aluminum_scaffold");
|
||||
@@ -21,6 +20,12 @@ public class TFMGSpriteShifts {
|
||||
public static final CTSpriteShiftEntry STEEL_ENCASED_COGWHEEL_SIDE = vertical("steel_encased_cogwheel_side"), STEEL_ENCASED_COGWHEEL_OTHERSIDE = horizontal("steel_encased_cogwheel_side"), HEAVY_CASING_ENCASED_COGWHEEL_SIDE = vertical("heavy_machinery_encased_cogwheel_side"), HEAVY_CASING_ENCASED_COGWHEEL_OTHERSIDE = horizontal("heavy_machinery_encased_cogwheel_side");
|
||||
public static final CTSpriteShiftEntry COKE_OVEN_TOP = getCT(AllCTTypes.RECTANGLE, "coke_oven/top"), COKE_OVEN_BOTTOM = getCT(AllCTTypes.RECTANGLE, "coke_oven/bottom"), COKE_OVEN_BACK = getCT(AllCTTypes.RECTANGLE, "coke_oven/side"), COKE_OVEN_SIDE = getCT(AllCTTypes.RECTANGLE, "coke_oven/side");
|
||||
|
||||
public static final CTSpriteShiftEntry FIREBOX_TOP = getCT(AllCTTypes.RECTANGLE, "firebox_top");
|
||||
|
||||
public static final CTSpriteShiftEntry STEEL_FLUID_TANK = getCT(AllCTTypes.RECTANGLE, "steel_fluid_tank"), STEEL_FLUID_TANK_TOP = getCT(AllCTTypes.RECTANGLE, "steel_fluid_tank_top"), STEEL_FLUID_TANK_INNER = getCT(AllCTTypes.RECTANGLE, "steel_fluid_tank_inner");
|
||||
public static final CTSpriteShiftEntry ALUMINUM_FLUID_TANK = getCT(AllCTTypes.RECTANGLE, "aluminum_fluid_tank"), ALUMINUM_FLUID_TANK_TOP = getCT(AllCTTypes.RECTANGLE, "aluminum_fluid_tank_top"), ALUMINUM_FLUID_TANK_INNER = getCT(AllCTTypes.RECTANGLE, "aluminum_fluid_tank_inner");
|
||||
public static final CTSpriteShiftEntry CAST_IRON_FLUID_TANK = getCT(AllCTTypes.RECTANGLE, "cast_iron_fluid_tank"), CAST_IRON_FLUID_TANK_TOP = getCT(AllCTTypes.RECTANGLE, "cast_iron_fluid_tank_top"), CAST_IRON_FLUID_TANK_INNER = getCT(AllCTTypes.RECTANGLE, "cast_iron_fluid_tank_inner");
|
||||
|
||||
public static final CTSpriteShiftEntry BLAST_FURNACE_REINFORCEMENT = vertical("blast_furnace_reinforcement");
|
||||
public static final CTSpriteShiftEntry RUSTED_BLAST_FURNACE_REINFORCEMENT = vertical("rusted_blast_furnace_reinforcement");
|
||||
public static final CTSpriteShiftEntry SEGMENTED_DISPLAY_SCREEN = horizontal("segmented_display_screen");
|
||||
|
||||
@@ -1,25 +1,36 @@
|
||||
package com.drmangotea.tfmg.base;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.drmangotea.tfmg.base.spark.ElectricSparkParticle;
|
||||
import com.drmangotea.tfmg.base.spark.Spark;
|
||||
import com.drmangotea.tfmg.content.electricity.connection.cables.CablePos;
|
||||
import com.drmangotea.tfmg.registry.TFMGEntityTypes;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.content.fluids.tank.FluidTankBlockEntity;
|
||||
import com.simibubi.create.foundation.fluid.SmartFluidTank;
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
import com.simibubi.create.foundation.utility.LangBuilder;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LightLayer;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
@@ -28,6 +39,7 @@ import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -57,6 +69,7 @@ public class TFMGUtils {
|
||||
}
|
||||
level.explode(null, pos.getX(), pos.getY(), pos.getZ(), radius, Level.ExplosionInteraction.BLOCK);
|
||||
}
|
||||
|
||||
public static void blowUpTank(FluidTankBlockEntity tank, int power) {
|
||||
|
||||
if (tank == null || tank.getControllerBE() == null) return;
|
||||
@@ -107,6 +120,7 @@ public class TFMGUtils {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static float getDistance(BlockPos pos1, BlockPos pos2, boolean _2D) {
|
||||
|
||||
|
||||
@@ -127,6 +141,7 @@ public class TFMGUtils {
|
||||
createFluidTooltip(be, tooltip);
|
||||
createItemTooltip(be, tooltip);
|
||||
}
|
||||
|
||||
public static boolean createFluidTooltip(BlockEntity be, List<Component> tooltip) {
|
||||
LangBuilder mb = Lang.translate("generic.unit.millibuckets");
|
||||
|
||||
@@ -187,7 +202,7 @@ public class TFMGUtils {
|
||||
}
|
||||
|
||||
public static String formatUnits(double n, String unit) {
|
||||
if(n == 0)
|
||||
if (n == 0)
|
||||
return Math.round(n) + unit;
|
||||
double var10000;
|
||||
if (n >= 1000000000) {
|
||||
@@ -200,34 +215,39 @@ public class TFMGUtils {
|
||||
var10000 = (double) Math.round((double) n / 100.0);
|
||||
return var10000 / 10.0 + "k" + unit;
|
||||
}
|
||||
// else if (n < 0.001) {
|
||||
// var10000 = (double) Math.round((double) n * 10000000.0);
|
||||
// return var10000 / 10.0 + "μ" + unit;
|
||||
// }
|
||||
// else if (n < 0.001) {
|
||||
// var10000 = (double) Math.round((double) n * 10000000.0);
|
||||
// return var10000 / 10.0 + "μ" + unit;
|
||||
// }
|
||||
else if (n < 1) {
|
||||
var10000 = (double) Math.round((double) n * 10000.0);
|
||||
return var10000 / 10.0 + "m" + unit;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return Math.round(n) + unit;
|
||||
}
|
||||
}
|
||||
public static void drainFilteredTank(SmartFluidTank tank, int amount){
|
||||
tank.setFluid(new FluidStack(tank.getFluid(),Math.max(tank.getFluidAmount()-amount,0)));
|
||||
|
||||
public static void drainFilteredTank(SmartFluidTank tank, int amount) {
|
||||
tank.setFluid(new FluidStack(tank.getFluid(), Math.max(tank.getFluidAmount() - amount, 0)));
|
||||
}
|
||||
public static void fillFilteredTank(SmartFluidTank tank, FluidStack resource){
|
||||
if(tank.getFluid().getFluid().isSame(resource.getFluid())||tank.isEmpty())
|
||||
tank.setFluid(new FluidStack(resource.getFluid(),Math.min(tank.getFluidAmount()+resource.getAmount(),tank.getCapacity())));
|
||||
|
||||
public static void fillFilteredTank(SmartFluidTank tank, FluidStack resource) {
|
||||
if (tank.getFluid().getFluid().isSame(resource.getFluid()) || tank.isEmpty())
|
||||
tank.setFluid(new FluidStack(resource.getFluid(), Math.min(tank.getFluidAmount() + resource.getAmount(), tank.getCapacity())));
|
||||
}
|
||||
|
||||
public static Iterable<BlockPos> AABBtoBlockPos(AABB aabb) {
|
||||
return BlockPos.betweenClosed(new BlockPos((int) aabb.minX, (int) aabb.minY, (int) aabb.minZ), new BlockPos((int) aabb.maxX, (int) aabb.maxY, (int) aabb.maxZ));
|
||||
}
|
||||
|
||||
public static SmartFluidTank createTank(int capacity, boolean extractionAllowed, Consumer<FluidStack> updateCallback) {
|
||||
return createTank(capacity, extractionAllowed, true, updateCallback, null);
|
||||
}
|
||||
|
||||
public static SmartFluidTank createTank(int capacity, boolean extractionAllowed, boolean insertionAllowed, Consumer<FluidStack> updateCallback) {
|
||||
return createTank(capacity, extractionAllowed, insertionAllowed, updateCallback, null);
|
||||
}
|
||||
|
||||
public static SmartFluidTank createTank(int capacity, boolean extractionAllowed, boolean insertionAllowed, Consumer<FluidStack> updateCallback, Fluid validFluid) {
|
||||
return new SmartFluidTank(capacity, updateCallback) {
|
||||
@Override
|
||||
@@ -237,16 +257,19 @@ public class TFMGUtils {
|
||||
|
||||
return stack.getFluid().isSame(validFluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(FluidStack resource, FluidAction action) {
|
||||
if (!extractionAllowed) return FluidStack.EMPTY;
|
||||
return super.drain(resource, action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(int maxDrain, FluidAction action) {
|
||||
if (!extractionAllowed) return FluidStack.EMPTY;
|
||||
return super.drain(maxDrain, action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, FluidAction action) {
|
||||
if (!insertionAllowed) return 0;
|
||||
@@ -254,4 +277,84 @@ public class TFMGUtils {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// //////////////////////
|
||||
public static void renderWire(Level level, PoseStack pMatrixStack, MultiBufferSource pBuffer, CablePos pos1, CablePos pos2,
|
||||
float curve, float r, float g, float b) {
|
||||
renderWire(level, pMatrixStack, pBuffer, pos1, pos2, curve, r, g, b, false);
|
||||
}
|
||||
|
||||
public static void renderWire(Level level, PoseStack pMatrixStack, MultiBufferSource pBuffer, CablePos pos1, CablePos pos2,
|
||||
float curve, float r, float g, float b, boolean flippedLighting) {
|
||||
pMatrixStack.pushPose();
|
||||
Vec3 vec3 = new Vec3(0, 0, 0);
|
||||
CablePos pos2Local = pos1.subtract(pos2);
|
||||
pMatrixStack.translate(0.5, 0.5, 0.5);
|
||||
vec3 = vec3.add(pos2Local.x() + 0.01, pos2Local.y(), pos2Local.z() + 0.01);
|
||||
float f = (float) (vec3.x);
|
||||
float f1 = (float) (vec3.y);
|
||||
float f2 = (float) (vec3.z);
|
||||
VertexConsumer vertexconsumer = pBuffer.getBuffer(RenderType.leash());
|
||||
Matrix4f matrix4f = pMatrixStack.last().pose();
|
||||
float f4 = (float) (Mth.fastInvSqrt(f * f + f2 * f2) * 0.025F / 2.0F);
|
||||
float f5 = f2 * f4;
|
||||
float f6 = f * f4;
|
||||
//int i =15;
|
||||
//int j = 15;
|
||||
|
||||
BlockPos blockpos2;
|
||||
BlockPos blockpos1;
|
||||
if (flippedLighting) {
|
||||
blockpos1 = new BlockPos((int) pos1.x(), (int) pos1.y(), (int) pos1.z());
|
||||
blockpos2 = new BlockPos((int) pos2.x(), (int) pos2.y(), (int) pos2.z());
|
||||
} else {
|
||||
blockpos2 = new BlockPos((int) pos1.x(), (int) pos1.y(), (int) pos1.z());
|
||||
blockpos1 = new BlockPos((int) pos2.x(), (int) pos2.y(), (int) pos2.z());
|
||||
}
|
||||
int i = level.getBrightness(LightLayer.SKY, blockpos1);
|
||||
int j = level.getBrightness(LightLayer.SKY, blockpos2);
|
||||
int k = level.getBrightness(LightLayer.SKY, blockpos1);
|
||||
int l = level.getBrightness(LightLayer.SKY, blockpos2);
|
||||
|
||||
|
||||
//int k = 15;
|
||||
//int l = 15;
|
||||
for (int i1 = 0; i1 <= 24; ++i1) {
|
||||
addVertexPair(vertexconsumer, matrix4f, f, f1, f2, i, j, k, l, 0.030F, 0.030F, f5, f6, i1, false, curve, r, g, b);
|
||||
}
|
||||
|
||||
for (int j1 = 24; j1 >= 0; --j1) {
|
||||
addVertexPair(vertexconsumer, matrix4f, f, f1, f2, i, j, k, l, 0.030F, 0.00F, f5, f6, j1, true, curve, r, g, b);
|
||||
}
|
||||
pMatrixStack.popPose();
|
||||
}
|
||||
|
||||
public static void debugMessage(Level level,String message){
|
||||
if(level.isClientSide){
|
||||
TFMG.LOGGER.debug("Client "+message);
|
||||
} else
|
||||
TFMG.LOGGER.debug("Server "+message);
|
||||
}
|
||||
|
||||
private static void addVertexPair(VertexConsumer vertexConsumer, Matrix4f matrix4f, float p_174310_, float p_174311_, float p_174312_, int light_1, int light_2, int p_174315_, int p_174316_, float thickness, float p_174318_, float p_174319_, float p_174320_, int value, boolean p_174322_, float curve, float r, float g, float b) {
|
||||
float f = (float) (value / 24.0F);
|
||||
int i = (int) Mth.lerp(f, (float) light_1, (float) light_2);
|
||||
int j = (int) Mth.lerp(f, (float) p_174315_, (float) p_174316_);
|
||||
int k = LightTexture.pack(i, j);
|
||||
float f1 = value % 2 == (p_174322_ ? 1 : 0) ? 0.7F : 1.0F;
|
||||
float red = r / 255 * f1;
|
||||
float green = g / 255 * f1;
|
||||
float blue = b / 255 * f1;
|
||||
float x = p_174310_ * f;
|
||||
|
||||
float pain;
|
||||
pain = ((value * curve * 24) - (value * value * curve)) * -1f;
|
||||
|
||||
float y = p_174311_ > 0.0F ? p_174311_ * f * f : p_174311_ - p_174311_ * (1.0F - f) * (1.0F - f);
|
||||
float z = p_174312_ * f;
|
||||
vertexConsumer.vertex(matrix4f, x - p_174319_, y + p_174318_ + pain, z + p_174320_).color(red, green, blue, 1.0F).uv2(k).endVertex();
|
||||
vertexConsumer.vertex(matrix4f, x + p_174319_, y + thickness - p_174318_ + pain, z - p_174320_).color(red, green, blue, 1.0F).uv2(k).endVertex();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.drmangotea.tfmg.base.events;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.content.equipment.toolbox.ToolboxHandler;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.event.level.LevelEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod.EventBusSubscriber
|
||||
public class TFMGCommonEvents {
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public static void playerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
Player player = event.getEntity();
|
||||
TFMG.DEPOSITS.playerLogin(player);
|
||||
}
|
||||
@SubscribeEvent
|
||||
public static void onLoadWorld(LevelEvent.Load event) {
|
||||
LevelAccessor world = event.getLevel();
|
||||
TFMG.DEPOSITS.levelLoaded(world);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.drmangotea.tfmg.base.fluid;
|
||||
|
||||
import com.drmangotea.tfmg.registry.TFMGFluids;
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.foundation.utility.Color;
|
||||
import com.tterrag.registrate.builders.FluidBuilder;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidType;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class GasFluidType extends FluidType {
|
||||
public GasFluidType(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
public static FluidBuilder.FluidTypeFactory create() {
|
||||
return (p, s, f) -> {
|
||||
HotFluidType fluidType = new HotFluidType(p, s, f);
|
||||
return fluidType;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDensity() {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.drmangotea.tfmg.content.misc;
|
||||
package com.drmangotea.tfmg.content.decoration;
|
||||
|
||||
import com.drmangotea.tfmg.content.items.weapons.lithium_blade.LithiumSpark;
|
||||
import com.drmangotea.tfmg.registry.TFMGEntityTypes;
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.foundation.block.ProperWaterloggedBlock;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
@@ -7,7 +7,7 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
public class RebarFloorBlock extends RebarBlock{
|
||||
public class RebarFloorBlock extends SimpleConcreteloggedBlock {
|
||||
public RebarFloorBlock(Properties p_49795_) {
|
||||
super(p_49795_);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
public class RebarWallBlock extends RebarBlock{
|
||||
public class RebarWallBlock extends SimpleConcreteloggedBlock {
|
||||
public RebarWallBlock(Properties p_49795_) {
|
||||
super(p_49795_);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.drmangotea.tfmg.content.decoration.concrete;
|
||||
|
||||
import com.drmangotea.tfmg.registry.TFMGBlocks;
|
||||
import com.drmangotea.tfmg.registry.TFMGFluids;
|
||||
import com.simibubi.create.foundation.block.ProperWaterloggedBlock;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
@@ -14,19 +12,15 @@ import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
|
||||
public class RebarBlock extends Block implements ConcreteloggedBlock {
|
||||
public class SimpleConcreteloggedBlock extends Block implements ConcreteloggedBlock {
|
||||
|
||||
|
||||
public RebarBlock(Properties p_49795_) {
|
||||
public SimpleConcreteloggedBlock(Properties p_49795_) {
|
||||
super(p_49795_);
|
||||
registerDefaultState(this.getStateDefinition().any().setValue(CONCRETELOGGED, false));
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.drmangotea.tfmg.content.decoration.tanks;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.content.decoration.tanks.steel.SteelTankBlockEntity;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.simibubi.create.content.fluids.tank.FluidTankBlockEntity;
|
||||
import com.simibubi.create.foundation.blockEntity.renderer.SafeBlockEntityRenderer;
|
||||
import com.simibubi.create.foundation.fluid.FluidRenderer;
|
||||
import com.simibubi.create.foundation.utility.animation.LerpedFloat;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.templates.FluidTank;
|
||||
|
||||
public class TFMGFluidTankRenderer extends SafeBlockEntityRenderer<FluidTankBlockEntity> {
|
||||
|
||||
public TFMGFluidTankRenderer(BlockEntityRendererProvider.Context context) {}
|
||||
@Override
|
||||
protected void renderSafe(FluidTankBlockEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
|
||||
int light, int overlay) {
|
||||
if (!te.isController())
|
||||
return;
|
||||
LerpedFloat fluidLevel = te.getFluidLevel();
|
||||
if (fluidLevel == null)
|
||||
return;
|
||||
|
||||
float capHeight = 1 / 4f;
|
||||
float tankHullWidth = 1 / 16f + 1 / 128f;
|
||||
float minPuddleHeight = 1 / 16f;
|
||||
float totalHeight = te.getHeight() - 2 * capHeight - minPuddleHeight;
|
||||
|
||||
float level = fluidLevel.getValue(partialTicks);
|
||||
if (level < 1 / (512f * totalHeight))
|
||||
return;
|
||||
float clampedLevel = Mth.clamp(level * totalHeight, 0, totalHeight);
|
||||
|
||||
FluidTank tank = (FluidTank) te.getTankInventory();
|
||||
FluidStack fluidStack = tank.getFluid();
|
||||
|
||||
if (fluidStack.isEmpty())
|
||||
return;
|
||||
boolean top = fluidStack.getFluid()
|
||||
.getFluidType()
|
||||
.isLighterThanAir();
|
||||
|
||||
float xMin = tankHullWidth;
|
||||
float xMax = xMin + te.getWidth() - 2 * tankHullWidth;
|
||||
float yMin = totalHeight + capHeight + minPuddleHeight - clampedLevel;
|
||||
float yMax = yMin + clampedLevel;
|
||||
|
||||
if (top) {
|
||||
yMin += totalHeight - clampedLevel;
|
||||
yMax += totalHeight - clampedLevel;
|
||||
}
|
||||
|
||||
float zMin = tankHullWidth;
|
||||
float zMax = zMin + te.getWidth() - 2 * tankHullWidth;
|
||||
|
||||
ms.pushPose();
|
||||
ms.translate(0, clampedLevel - totalHeight, 0);
|
||||
FluidRenderer.renderFluidBox(fluidStack, xMin, yMin, zMin, xMax, yMax, zMax, buffer, ms, light, false);
|
||||
ms.popPose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderOffScreen(FluidTankBlockEntity te) {
|
||||
return te.isController();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.drmangotea.tfmg.content.decoration.tank;
|
||||
package com.drmangotea.tfmg.content.decoration.tanks;
|
||||
|
||||
import com.drmangotea.tfmg.content.decoration.tanks.steel.SteelTankBlock;
|
||||
import com.simibubi.create.content.fluids.tank.FluidTankBlock;
|
||||
import com.simibubi.create.foundation.data.AssetLookup;
|
||||
import com.simibubi.create.foundation.data.SpecialBlockStateGen;
|
||||
import com.tterrag.registrate.providers.DataGenContext;
|
||||
@@ -8,15 +10,15 @@ import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.client.model.generators.ModelFile;
|
||||
|
||||
public class SteelTankGenerator extends SpecialBlockStateGen {
|
||||
public class TFMGTankGenerator extends SpecialBlockStateGen {
|
||||
|
||||
private String prefix;
|
||||
|
||||
public SteelTankGenerator() {
|
||||
public TFMGTankGenerator() {
|
||||
this("");
|
||||
}
|
||||
|
||||
public SteelTankGenerator(String prefix) {
|
||||
public TFMGTankGenerator(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
@@ -35,7 +37,7 @@ public class SteelTankGenerator extends SpecialBlockStateGen {
|
||||
BlockState state) {
|
||||
Boolean top = state.getValue(SteelTankBlock.TOP);
|
||||
Boolean bottom = state.getValue(SteelTankBlock.BOTTOM);
|
||||
SteelTankBlock.Shape shape = state.getValue(SteelTankBlock.SHAPE);
|
||||
FluidTankBlock.Shape shape = state.getValue(SteelTankBlock.SHAPE);
|
||||
|
||||
String shapeName = "middle";
|
||||
if (top && bottom)
|
||||
@@ -45,7 +47,7 @@ public class SteelTankGenerator extends SpecialBlockStateGen {
|
||||
else if (bottom)
|
||||
shapeName = "bottom";
|
||||
|
||||
String modelName = shapeName + (shape == SteelTankBlock.Shape.PLAIN ? "" : "_" + shape.getSerializedName());
|
||||
String modelName = shapeName + (shape == FluidTankBlock.Shape.PLAIN ? "" : "_" + shape.getSerializedName());
|
||||
|
||||
if (!prefix.isEmpty())
|
||||
return prov.models()
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.drmangotea.tfmg.content.decoration.tanks.aluminum;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.base.TFMGSpriteShifts;
|
||||
import com.simibubi.create.api.connectivity.ConnectivityHandler;
|
||||
import com.simibubi.create.content.fluids.tank.FluidTankCTBehaviour;
|
||||
import com.simibubi.create.foundation.block.connected.CTModel;
|
||||
import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry;
|
||||
import com.simibubi.create.foundation.utility.Iterate;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.client.model.data.ModelData;
|
||||
import net.minecraftforge.client.model.data.ModelProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class AluminumFluidTankModel extends CTModel {
|
||||
|
||||
protected static final ModelProperty<CullData> CULL_PROPERTY = new ModelProperty<>();
|
||||
|
||||
public static AluminumFluidTankModel standard(BakedModel originalModel) {
|
||||
return new AluminumFluidTankModel(originalModel, TFMGSpriteShifts.ALUMINUM_FLUID_TANK, TFMGSpriteShifts.ALUMINUM_FLUID_TANK_TOP,
|
||||
TFMGSpriteShifts.ALUMINUM_FLUID_TANK_INNER);
|
||||
}
|
||||
|
||||
|
||||
private AluminumFluidTankModel(BakedModel originalModel, CTSpriteShiftEntry side, CTSpriteShiftEntry top,
|
||||
CTSpriteShiftEntry inner) {
|
||||
super(originalModel, new FluidTankCTBehaviour(side, top, inner));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModelData.Builder gatherModelData(ModelData.Builder builder, BlockAndTintGetter world, BlockPos pos, BlockState state,
|
||||
ModelData blockEntityData) {
|
||||
super.gatherModelData(builder, world, pos, state, blockEntityData);
|
||||
CullData cullData = new CullData();
|
||||
for (Direction d : Iterate.horizontalDirections)
|
||||
cullData.setCulled(d, ConnectivityHandler.isConnected(world, pos, pos.relative(d)));
|
||||
return builder.with(CULL_PROPERTY, cullData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(BlockState state, Direction side, RandomSource rand, ModelData extraData, RenderType renderType) {
|
||||
if (side != null)
|
||||
return Collections.emptyList();
|
||||
|
||||
List<BakedQuad> quads = new ArrayList<>();
|
||||
for (Direction d : Iterate.directions) {
|
||||
if (extraData.has(CULL_PROPERTY) && extraData.get(CULL_PROPERTY)
|
||||
.isCulled(d))
|
||||
continue;
|
||||
quads.addAll(super.getQuads(state, d, rand, extraData, renderType));
|
||||
}
|
||||
quads.addAll(super.getQuads(state, null, rand, extraData, renderType));
|
||||
return quads;
|
||||
}
|
||||
private class CullData {
|
||||
boolean[] culledFaces;
|
||||
|
||||
public CullData() {
|
||||
culledFaces = new boolean[4];
|
||||
Arrays.fill(culledFaces, false);
|
||||
}
|
||||
|
||||
void setCulled(Direction face, boolean cull) {
|
||||
if (face.getAxis()
|
||||
.isVertical())
|
||||
return;
|
||||
culledFaces[face.get2DDataValue()] = cull;
|
||||
}
|
||||
|
||||
boolean isCulled(Direction face) {
|
||||
if (face.getAxis()
|
||||
.isVertical())
|
||||
return false;
|
||||
return culledFaces[face.get2DDataValue()];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,322 @@
|
||||
package com.drmangotea.tfmg.content.decoration.tanks.aluminum;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.mixin.accessor.FluidTankBlockEntityAccessor;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.simibubi.create.api.connectivity.ConnectivityHandler;
|
||||
import com.simibubi.create.content.equipment.wrench.IWrenchable;
|
||||
import com.simibubi.create.content.fluids.tank.FluidTankBlock;
|
||||
import com.simibubi.create.content.fluids.tank.FluidTankBlockEntity;
|
||||
import com.simibubi.create.content.fluids.transfer.GenericItemEmptying;
|
||||
import com.simibubi.create.content.fluids.transfer.GenericItemFilling;
|
||||
import com.simibubi.create.foundation.block.IBE;
|
||||
import com.simibubi.create.foundation.blockEntity.ComparatorUtil;
|
||||
import com.simibubi.create.foundation.fluid.FluidHelper;
|
||||
import com.simibubi.create.foundation.fluid.FluidHelper.FluidExchange;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.particles.BlockParticleOption;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Mirror;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition.Builder;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
import net.minecraftforge.common.util.ForgeSoundType;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
|
||||
import static com.simibubi.create.content.fluids.tank.FluidTankBlock.Shape;
|
||||
|
||||
public class AluminumTankBlock extends Block implements IWrenchable, IBE<FluidTankBlockEntity> {
|
||||
public static final BooleanProperty TOP = FluidTankBlock.TOP;
|
||||
public static final BooleanProperty BOTTOM = FluidTankBlock.BOTTOM;
|
||||
public static final EnumProperty<Shape> SHAPE = FluidTankBlock.SHAPE;
|
||||
private boolean creative;
|
||||
public static AluminumTankBlock regular(Properties p_i48440_1_) {
|
||||
return new AluminumTankBlock(p_i48440_1_, false);
|
||||
}
|
||||
|
||||
protected AluminumTankBlock(Properties p_i48440_1_, boolean creative) {
|
||||
super(p_i48440_1_);
|
||||
this.creative = creative;
|
||||
registerDefaultState(defaultBlockState().setValue(TOP, true)
|
||||
.setValue(BOTTOM, true)
|
||||
.setValue(SHAPE, Shape.WINDOW));
|
||||
}
|
||||
|
||||
public static boolean isTank(BlockState state) {
|
||||
return state.getBlock() instanceof AluminumTankBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean moved) {
|
||||
if (oldState.getBlock() == state.getBlock())
|
||||
return;
|
||||
if (moved)
|
||||
return;
|
||||
withBlockEntityDo(world, pos, b -> ((FluidTankBlockEntityAccessor)b).tfmg$updateConnectivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(Builder<Block, BlockState> p_206840_1_) {
|
||||
p_206840_1_.add(TOP, BOTTOM, SHAPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightEmission(BlockState state, BlockGetter world, BlockPos pos) {
|
||||
FluidTankBlockEntity tankAt = ConnectivityHandler.partAt(getBlockEntityType(), world, pos);
|
||||
if (tankAt == null)
|
||||
return 0;
|
||||
FluidTankBlockEntity controllerTE = (FluidTankBlockEntity) tankAt.getControllerBE();
|
||||
if (controllerTE == null || !((FluidTankBlockEntityAccessor)controllerTE).tfmg$getWindow())
|
||||
return 0;
|
||||
return ((FluidTankBlockEntityAccessor)tankAt).tfmg$getLuminosity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult onWrenched(BlockState state, UseOnContext context) {
|
||||
withBlockEntityDo(context.getLevel(), context.getClickedPos(), FluidTankBlockEntity::toggleWindows);
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
static final VoxelShape CAMPFIRE_SMOKE_CLIP = Block.box(0, 4, 0, 16, 16, 16);
|
||||
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState pState, BlockGetter pLevel, BlockPos pPos,
|
||||
CollisionContext pContext) {
|
||||
if (pContext == CollisionContext.empty())
|
||||
return CAMPFIRE_SMOKE_CLIP;
|
||||
return pState.getShape(pLevel, pPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getBlockSupportShape(BlockState pState, BlockGetter pReader, BlockPos pPos) {
|
||||
return Shapes.block();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState updateShape(BlockState pState, Direction pDirection, BlockState pNeighborState,
|
||||
LevelAccessor pLevel, BlockPos pCurrentPos, BlockPos pNeighborPos) {
|
||||
if (pDirection == Direction.DOWN && pNeighborState.getBlock() != this)
|
||||
withBlockEntityDo(pLevel, pCurrentPos, FluidTankBlockEntity::updateBoilerTemperature);
|
||||
return pState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand,
|
||||
BlockHitResult ray) {
|
||||
ItemStack heldItem = player.getItemInHand(hand);
|
||||
boolean onClient = world.isClientSide;
|
||||
|
||||
if (heldItem.isEmpty())
|
||||
return InteractionResult.PASS;
|
||||
if (!player.isCreative() && !creative)
|
||||
return InteractionResult.PASS;
|
||||
|
||||
FluidExchange exchange = null;
|
||||
FluidTankBlockEntity te = ConnectivityHandler.partAt(getBlockEntityType(), world, pos);
|
||||
if (te == null)
|
||||
return InteractionResult.FAIL;
|
||||
|
||||
LazyOptional<IFluidHandler> tankCapability = te.getCapability(ForgeCapabilities.FLUID_HANDLER);
|
||||
if (!tankCapability.isPresent())
|
||||
return InteractionResult.PASS;
|
||||
IFluidHandler fluidTank = tankCapability.orElse(null);
|
||||
FluidStack prevFluidInTank = fluidTank.getFluidInTank(0)
|
||||
.copy();
|
||||
|
||||
if (FluidHelper.tryEmptyItemIntoBE(world, player, hand, heldItem, te))
|
||||
exchange = FluidExchange.ITEM_TO_TANK;
|
||||
else if (FluidHelper.tryFillItemFromBE(world, player, hand, heldItem, te))
|
||||
exchange = FluidExchange.TANK_TO_ITEM;
|
||||
|
||||
if (exchange == null) {
|
||||
if (GenericItemEmptying.canItemBeEmptied(world, heldItem)
|
||||
|| GenericItemFilling.canItemBeFilled(world, heldItem))
|
||||
return InteractionResult.SUCCESS;
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
SoundEvent soundevent = null;
|
||||
BlockState fluidState = null;
|
||||
FluidStack fluidInTank = tankCapability.map(fh -> fh.getFluidInTank(0))
|
||||
.orElse(FluidStack.EMPTY);
|
||||
|
||||
if (exchange == FluidExchange.ITEM_TO_TANK) {
|
||||
|
||||
|
||||
Fluid fluid = fluidInTank.getFluid();
|
||||
fluidState = fluid.defaultFluidState()
|
||||
.createLegacyBlock();
|
||||
soundevent = FluidHelper.getEmptySound(fluidInTank);
|
||||
}
|
||||
|
||||
if (exchange == FluidExchange.TANK_TO_ITEM) {
|
||||
|
||||
Fluid fluid = prevFluidInTank.getFluid();
|
||||
fluidState = fluid.defaultFluidState()
|
||||
.createLegacyBlock();
|
||||
soundevent = FluidHelper.getFillSound(prevFluidInTank);
|
||||
}
|
||||
|
||||
if (soundevent != null && !onClient) {
|
||||
float pitch = Mth
|
||||
.clamp(1 - (1f * fluidInTank.getAmount() / (FluidTankBlockEntity.getCapacityMultiplier() * 16)), 0, 1);
|
||||
pitch /= 1.5f;
|
||||
pitch += .5f;
|
||||
pitch += (world.random.nextFloat() - .5f) / 4f;
|
||||
world.playSound(null, pos, soundevent, SoundSource.BLOCKS, .5f, pitch);
|
||||
}
|
||||
|
||||
if (!fluidInTank.isFluidStackIdentical(prevFluidInTank)) {
|
||||
if (te instanceof FluidTankBlockEntity) {
|
||||
FluidTankBlockEntity controllerTE = (FluidTankBlockEntity) ((FluidTankBlockEntity) te).getControllerBE();
|
||||
if (controllerTE != null) {
|
||||
if (fluidState != null && onClient) {
|
||||
BlockParticleOption blockParticleData =
|
||||
new BlockParticleOption(ParticleTypes.BLOCK, fluidState);
|
||||
float level = (float) fluidInTank.getAmount() / fluidTank.getTankCapacity(0);
|
||||
|
||||
boolean reversed = fluidInTank.getFluid()
|
||||
.getFluidType()
|
||||
.isLighterThanAir();
|
||||
if (reversed)
|
||||
level = 1 - level;
|
||||
|
||||
Vec3 vec = ray.getLocation();
|
||||
vec = new Vec3(vec.x, controllerTE.getBlockPos()
|
||||
.getY() + level * (controllerTE.getHeight() - .5f) + .25f, vec.z);
|
||||
Vec3 motion = player.position()
|
||||
.subtract(vec)
|
||||
.scale(1 / 20f);
|
||||
vec = vec.add(motion);
|
||||
world.addParticle(blockParticleData, vec.x, vec.y, vec.z, motion.x, motion.y, motion.z);
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
controllerTE.sendDataImmediately();
|
||||
controllerTE.setChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level world, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
if (state.hasBlockEntity() && (state.getBlock() != newState.getBlock() || !newState.hasBlockEntity())) {
|
||||
BlockEntity te = world.getBlockEntity(pos);
|
||||
if (!(te instanceof FluidTankBlockEntity))
|
||||
return;
|
||||
FluidTankBlockEntity tankTE = (FluidTankBlockEntity) te;
|
||||
world.removeBlockEntity(pos);
|
||||
ConnectivityHandler.splitMulti(tankTE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<FluidTankBlockEntity> getBlockEntityClass() {
|
||||
return FluidTankBlockEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntityType<? extends FluidTankBlockEntity> getBlockEntityType() {
|
||||
return TFMGBlockEntities.TFMG_FLUID_TANK.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState mirror(BlockState state, Mirror mirror) {
|
||||
if (mirror == Mirror.NONE)
|
||||
return state;
|
||||
boolean x = mirror == Mirror.FRONT_BACK;
|
||||
switch (state.getValue(SHAPE)) {
|
||||
case WINDOW_NE:
|
||||
return state.setValue(SHAPE, x ? Shape.WINDOW_NW : Shape.WINDOW_SE);
|
||||
case WINDOW_NW:
|
||||
return state.setValue(SHAPE, x ? Shape.WINDOW_NE : Shape.WINDOW_SW);
|
||||
case WINDOW_SE:
|
||||
return state.setValue(SHAPE, x ? Shape.WINDOW_SW : Shape.WINDOW_NE);
|
||||
case WINDOW_SW:
|
||||
return state.setValue(SHAPE, x ? Shape.WINDOW_SE : Shape.WINDOW_NW);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, Rotation rotation) {
|
||||
for (int i = 0; i < rotation.ordinal(); i++)
|
||||
state = rotateOnce(state);
|
||||
return state;
|
||||
}
|
||||
|
||||
private BlockState rotateOnce(BlockState state) {
|
||||
switch (state.getValue(SHAPE)) {
|
||||
case WINDOW_NE:
|
||||
return state.setValue(SHAPE, Shape.WINDOW_SE);
|
||||
case WINDOW_NW:
|
||||
return state.setValue(SHAPE, Shape.WINDOW_NE);
|
||||
case WINDOW_SE:
|
||||
return state.setValue(SHAPE, Shape.WINDOW_SW);
|
||||
case WINDOW_SW:
|
||||
return state.setValue(SHAPE, Shape.WINDOW_NW);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Tanks are less noisy when placed in batch
|
||||
public static final SoundType SILENCED_METAL =
|
||||
new ForgeSoundType(0.1F, 1.5F, () -> SoundEvents.METAL_BREAK, () -> SoundEvents.METAL_STEP,
|
||||
() -> SoundEvents.METAL_PLACE, () -> SoundEvents.METAL_HIT, () -> SoundEvents.METAL_FALL);
|
||||
|
||||
@Override
|
||||
public SoundType getSoundType(BlockState state, LevelReader world, BlockPos pos, Entity entity) {
|
||||
SoundType soundType = super.getSoundType(state, world, pos, entity);
|
||||
if (entity != null && entity.getPersistentData()
|
||||
.contains("SilenceTankSound"))
|
||||
return SILENCED_METAL;
|
||||
return soundType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAnalogOutputSignal(BlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAnalogOutputSignal(BlockState blockState, Level worldIn, BlockPos pos) {
|
||||
return getBlockEntityOptional(worldIn, pos).map(FluidTankBlockEntity::getControllerBE)
|
||||
.map(te -> ComparatorUtil.fractionToRedstoneLevel(te.getFillState()))
|
||||
.orElse(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.drmangotea.tfmg.content.decoration.tanks.aluminum;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.simibubi.create.api.connectivity.ConnectivityHandler;
|
||||
import com.simibubi.create.content.fluids.tank.FluidTankBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public class AluminumTankItem extends BlockItem {
|
||||
|
||||
public AluminumTankItem(Block p_i48527_1_, Properties p_i48527_2_) {
|
||||
super(p_i48527_1_, p_i48527_2_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult place(BlockPlaceContext ctx) {
|
||||
InteractionResult initialResult = super.place(ctx);
|
||||
if (!initialResult.consumesAction())
|
||||
return initialResult;
|
||||
tryMultiPlace(ctx);
|
||||
return initialResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean updateCustomBlockEntityTag(BlockPos p_195943_1_, Level p_195943_2_, Player p_195943_3_,
|
||||
ItemStack p_195943_4_, BlockState p_195943_5_) {
|
||||
MinecraftServer minecraftserver = p_195943_2_.getServer();
|
||||
if (minecraftserver == null)
|
||||
return false;
|
||||
CompoundTag nbt = p_195943_4_.getTagElement("BlockEntityTag");
|
||||
if (nbt != null) {
|
||||
nbt.remove("Luminosity");
|
||||
nbt.remove("Size");
|
||||
nbt.remove("Height");
|
||||
nbt.remove("Controller");
|
||||
nbt.remove("LastKnownPos");
|
||||
if (nbt.contains("TankContent")) {
|
||||
FluidStack fluid = FluidStack.loadFluidStackFromNBT(nbt.getCompound("TankContent"));
|
||||
if (!fluid.isEmpty()) {
|
||||
fluid.setAmount(Math.min(FluidTankBlockEntity.getCapacityMultiplier(), fluid.getAmount()));
|
||||
nbt.put("TankContent", fluid.writeToNBT(new CompoundTag()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.updateCustomBlockEntityTag(p_195943_1_, p_195943_2_, p_195943_3_, p_195943_4_, p_195943_5_);
|
||||
}
|
||||
|
||||
private void tryMultiPlace(BlockPlaceContext ctx) {
|
||||
|
||||
Player player = ctx.getPlayer();
|
||||
if (player == null)
|
||||
return;
|
||||
if (player.isShiftKeyDown())
|
||||
return;
|
||||
Direction face = ctx.getClickedFace();
|
||||
if (!face.getAxis()
|
||||
.isVertical())
|
||||
return;
|
||||
ItemStack stack = ctx.getItemInHand();
|
||||
Level world = ctx.getLevel();
|
||||
BlockPos pos = ctx.getClickedPos();
|
||||
BlockPos placedOnPos = pos.relative(face.getOpposite());
|
||||
BlockState placedOnState = world.getBlockState(placedOnPos);
|
||||
|
||||
if (!AluminumTankBlock.isTank(placedOnState))
|
||||
return;
|
||||
|
||||
FluidTankBlockEntity tankAt = ConnectivityHandler.partAt(
|
||||
TFMGBlockEntities.TFMG_FLUID_TANK.get(), world, placedOnPos
|
||||
);
|
||||
if (tankAt == null)
|
||||
return;
|
||||
FluidTankBlockEntity controllerTE = tankAt.getControllerBE();
|
||||
if (controllerTE == null)
|
||||
return;
|
||||
|
||||
int width = controllerTE.getWidth();
|
||||
if (width == 1)
|
||||
return;
|
||||
|
||||
int tanksToPlace = 0;
|
||||
BlockPos startPos = face == Direction.DOWN ? controllerTE.getBlockPos()
|
||||
.below()
|
||||
: controllerTE.getBlockPos()
|
||||
.above(controllerTE.getHeight());
|
||||
|
||||
if (startPos.getY() != pos.getY())
|
||||
return;
|
||||
|
||||
for (int xOffset = 0; xOffset < width; xOffset++) {
|
||||
for (int zOffset = 0; zOffset < width; zOffset++) {
|
||||
BlockPos offsetPos = startPos.offset(xOffset, 0, zOffset);
|
||||
BlockState blockState = world.getBlockState(offsetPos);
|
||||
if (AluminumTankBlock.isTank(blockState))
|
||||
continue;
|
||||
if (!blockState.canBeReplaced())
|
||||
return;
|
||||
tanksToPlace++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!player.isCreative() && stack.getCount() < tanksToPlace)
|
||||
return;
|
||||
|
||||
for (int xOffset = 0; xOffset < width; xOffset++) {
|
||||
for (int zOffset = 0; zOffset < width; zOffset++) {
|
||||
BlockPos offsetPos = startPos.offset(xOffset, 0, zOffset);
|
||||
BlockState blockState = world.getBlockState(offsetPos);
|
||||
if (AluminumTankBlock.isTank(blockState))
|
||||
continue;
|
||||
BlockPlaceContext context = BlockPlaceContext.at(ctx, offsetPos, face);
|
||||
player.getPersistentData()
|
||||
.putBoolean("SilenceTankSound", true);
|
||||
super.place(context);
|
||||
player.getPersistentData()
|
||||
.remove("SilenceTankSound");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.drmangotea.tfmg.content.decoration.tanks.cast_iron;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.base.TFMGSpriteShifts;
|
||||
import com.simibubi.create.api.connectivity.ConnectivityHandler;
|
||||
import com.simibubi.create.content.fluids.tank.FluidTankCTBehaviour;
|
||||
import com.simibubi.create.foundation.block.connected.CTModel;
|
||||
import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry;
|
||||
import com.simibubi.create.foundation.utility.Iterate;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.client.model.data.ModelData;
|
||||
import net.minecraftforge.client.model.data.ModelProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CastIronFluidTankModel extends CTModel {
|
||||
|
||||
protected static final ModelProperty<CullData> CULL_PROPERTY = new ModelProperty<>();
|
||||
|
||||
public static CastIronFluidTankModel standard(BakedModel originalModel) {
|
||||
return new CastIronFluidTankModel(originalModel, TFMGSpriteShifts.CAST_IRON_FLUID_TANK, TFMGSpriteShifts.CAST_IRON_FLUID_TANK_TOP,
|
||||
TFMGSpriteShifts.CAST_IRON_FLUID_TANK_INNER);
|
||||
}
|
||||
|
||||
|
||||
private CastIronFluidTankModel(BakedModel originalModel, CTSpriteShiftEntry side, CTSpriteShiftEntry top,
|
||||
CTSpriteShiftEntry inner) {
|
||||
super(originalModel, new FluidTankCTBehaviour(side, top, inner));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModelData.Builder gatherModelData(ModelData.Builder builder, BlockAndTintGetter world, BlockPos pos, BlockState state,
|
||||
ModelData blockEntityData) {
|
||||
super.gatherModelData(builder, world, pos, state, blockEntityData);
|
||||
CullData cullData = new CullData();
|
||||
for (Direction d : Iterate.horizontalDirections)
|
||||
cullData.setCulled(d, ConnectivityHandler.isConnected(world, pos, pos.relative(d)));
|
||||
return builder.with(CULL_PROPERTY, cullData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(BlockState state, Direction side, RandomSource rand, ModelData extraData, RenderType renderType) {
|
||||
if (side != null)
|
||||
return Collections.emptyList();
|
||||
|
||||
List<BakedQuad> quads = new ArrayList<>();
|
||||
for (Direction d : Iterate.directions) {
|
||||
if (extraData.has(CULL_PROPERTY) && extraData.get(CULL_PROPERTY)
|
||||
.isCulled(d))
|
||||
continue;
|
||||
quads.addAll(super.getQuads(state, d, rand, extraData, renderType));
|
||||
}
|
||||
quads.addAll(super.getQuads(state, null, rand, extraData, renderType));
|
||||
return quads;
|
||||
}
|
||||
private class CullData {
|
||||
boolean[] culledFaces;
|
||||
|
||||
public CullData() {
|
||||
culledFaces = new boolean[4];
|
||||
Arrays.fill(culledFaces, false);
|
||||
}
|
||||
|
||||
void setCulled(Direction face, boolean cull) {
|
||||
if (face.getAxis()
|
||||
.isVertical())
|
||||
return;
|
||||
culledFaces[face.get2DDataValue()] = cull;
|
||||
}
|
||||
|
||||
boolean isCulled(Direction face) {
|
||||
if (face.getAxis()
|
||||
.isVertical())
|
||||
return false;
|
||||
return culledFaces[face.get2DDataValue()];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,322 @@
|
||||
package com.drmangotea.tfmg.content.decoration.tanks.cast_iron;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.mixin.accessor.FluidTankBlockEntityAccessor;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.simibubi.create.api.connectivity.ConnectivityHandler;
|
||||
import com.simibubi.create.content.equipment.wrench.IWrenchable;
|
||||
import com.simibubi.create.content.fluids.tank.FluidTankBlock;
|
||||
import com.simibubi.create.content.fluids.tank.FluidTankBlockEntity;
|
||||
import com.simibubi.create.content.fluids.transfer.GenericItemEmptying;
|
||||
import com.simibubi.create.content.fluids.transfer.GenericItemFilling;
|
||||
import com.simibubi.create.foundation.block.IBE;
|
||||
import com.simibubi.create.foundation.blockEntity.ComparatorUtil;
|
||||
import com.simibubi.create.foundation.fluid.FluidHelper;
|
||||
import com.simibubi.create.foundation.fluid.FluidHelper.FluidExchange;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.particles.BlockParticleOption;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Mirror;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition.Builder;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
import net.minecraftforge.common.util.ForgeSoundType;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
|
||||
import static com.simibubi.create.content.fluids.tank.FluidTankBlock.Shape;
|
||||
|
||||
public class CastIronTankBlock extends Block implements IWrenchable, IBE<FluidTankBlockEntity> {
|
||||
public static final BooleanProperty TOP = FluidTankBlock.TOP;
|
||||
public static final BooleanProperty BOTTOM = FluidTankBlock.BOTTOM;
|
||||
public static final EnumProperty<Shape> SHAPE = FluidTankBlock.SHAPE;
|
||||
private boolean creative;
|
||||
public static CastIronTankBlock regular(Properties p_i48440_1_) {
|
||||
return new CastIronTankBlock(p_i48440_1_, false);
|
||||
}
|
||||
|
||||
protected CastIronTankBlock(Properties p_i48440_1_, boolean creative) {
|
||||
super(p_i48440_1_);
|
||||
this.creative = creative;
|
||||
registerDefaultState(defaultBlockState().setValue(TOP, true)
|
||||
.setValue(BOTTOM, true)
|
||||
.setValue(SHAPE, Shape.WINDOW));
|
||||
}
|
||||
|
||||
public static boolean isTank(BlockState state) {
|
||||
return state.getBlock() instanceof CastIronTankBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean moved) {
|
||||
if (oldState.getBlock() == state.getBlock())
|
||||
return;
|
||||
if (moved)
|
||||
return;
|
||||
withBlockEntityDo(world, pos, b -> ((FluidTankBlockEntityAccessor)b).tfmg$updateConnectivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(Builder<Block, BlockState> p_206840_1_) {
|
||||
p_206840_1_.add(TOP, BOTTOM, SHAPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightEmission(BlockState state, BlockGetter world, BlockPos pos) {
|
||||
FluidTankBlockEntity tankAt = ConnectivityHandler.partAt(getBlockEntityType(), world, pos);
|
||||
if (tankAt == null)
|
||||
return 0;
|
||||
FluidTankBlockEntity controllerTE = (FluidTankBlockEntity) tankAt.getControllerBE();
|
||||
if (controllerTE == null || !((FluidTankBlockEntityAccessor)controllerTE).tfmg$getWindow())
|
||||
return 0;
|
||||
return ((FluidTankBlockEntityAccessor)tankAt).tfmg$getLuminosity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult onWrenched(BlockState state, UseOnContext context) {
|
||||
withBlockEntityDo(context.getLevel(), context.getClickedPos(), FluidTankBlockEntity::toggleWindows);
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
static final VoxelShape CAMPFIRE_SMOKE_CLIP = Block.box(0, 4, 0, 16, 16, 16);
|
||||
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState pState, BlockGetter pLevel, BlockPos pPos,
|
||||
CollisionContext pContext) {
|
||||
if (pContext == CollisionContext.empty())
|
||||
return CAMPFIRE_SMOKE_CLIP;
|
||||
return pState.getShape(pLevel, pPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getBlockSupportShape(BlockState pState, BlockGetter pReader, BlockPos pPos) {
|
||||
return Shapes.block();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState updateShape(BlockState pState, Direction pDirection, BlockState pNeighborState,
|
||||
LevelAccessor pLevel, BlockPos pCurrentPos, BlockPos pNeighborPos) {
|
||||
if (pDirection == Direction.DOWN && pNeighborState.getBlock() != this)
|
||||
withBlockEntityDo(pLevel, pCurrentPos, FluidTankBlockEntity::updateBoilerTemperature);
|
||||
return pState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand,
|
||||
BlockHitResult ray) {
|
||||
ItemStack heldItem = player.getItemInHand(hand);
|
||||
boolean onClient = world.isClientSide;
|
||||
|
||||
if (heldItem.isEmpty())
|
||||
return InteractionResult.PASS;
|
||||
if (!player.isCreative() && !creative)
|
||||
return InteractionResult.PASS;
|
||||
|
||||
FluidExchange exchange = null;
|
||||
FluidTankBlockEntity te = ConnectivityHandler.partAt(getBlockEntityType(), world, pos);
|
||||
if (te == null)
|
||||
return InteractionResult.FAIL;
|
||||
|
||||
LazyOptional<IFluidHandler> tankCapability = te.getCapability(ForgeCapabilities.FLUID_HANDLER);
|
||||
if (!tankCapability.isPresent())
|
||||
return InteractionResult.PASS;
|
||||
IFluidHandler fluidTank = tankCapability.orElse(null);
|
||||
FluidStack prevFluidInTank = fluidTank.getFluidInTank(0)
|
||||
.copy();
|
||||
|
||||
if (FluidHelper.tryEmptyItemIntoBE(world, player, hand, heldItem, te))
|
||||
exchange = FluidExchange.ITEM_TO_TANK;
|
||||
else if (FluidHelper.tryFillItemFromBE(world, player, hand, heldItem, te))
|
||||
exchange = FluidExchange.TANK_TO_ITEM;
|
||||
|
||||
if (exchange == null) {
|
||||
if (GenericItemEmptying.canItemBeEmptied(world, heldItem)
|
||||
|| GenericItemFilling.canItemBeFilled(world, heldItem))
|
||||
return InteractionResult.SUCCESS;
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
SoundEvent soundevent = null;
|
||||
BlockState fluidState = null;
|
||||
FluidStack fluidInTank = tankCapability.map(fh -> fh.getFluidInTank(0))
|
||||
.orElse(FluidStack.EMPTY);
|
||||
|
||||
if (exchange == FluidExchange.ITEM_TO_TANK) {
|
||||
|
||||
|
||||
Fluid fluid = fluidInTank.getFluid();
|
||||
fluidState = fluid.defaultFluidState()
|
||||
.createLegacyBlock();
|
||||
soundevent = FluidHelper.getEmptySound(fluidInTank);
|
||||
}
|
||||
|
||||
if (exchange == FluidExchange.TANK_TO_ITEM) {
|
||||
|
||||
Fluid fluid = prevFluidInTank.getFluid();
|
||||
fluidState = fluid.defaultFluidState()
|
||||
.createLegacyBlock();
|
||||
soundevent = FluidHelper.getFillSound(prevFluidInTank);
|
||||
}
|
||||
|
||||
if (soundevent != null && !onClient) {
|
||||
float pitch = Mth
|
||||
.clamp(1 - (1f * fluidInTank.getAmount() / (FluidTankBlockEntity.getCapacityMultiplier() * 16)), 0, 1);
|
||||
pitch /= 1.5f;
|
||||
pitch += .5f;
|
||||
pitch += (world.random.nextFloat() - .5f) / 4f;
|
||||
world.playSound(null, pos, soundevent, SoundSource.BLOCKS, .5f, pitch);
|
||||
}
|
||||
|
||||
if (!fluidInTank.isFluidStackIdentical(prevFluidInTank)) {
|
||||
if (te instanceof FluidTankBlockEntity) {
|
||||
FluidTankBlockEntity controllerTE = (FluidTankBlockEntity) ((FluidTankBlockEntity) te).getControllerBE();
|
||||
if (controllerTE != null) {
|
||||
if (fluidState != null && onClient) {
|
||||
BlockParticleOption blockParticleData =
|
||||
new BlockParticleOption(ParticleTypes.BLOCK, fluidState);
|
||||
float level = (float) fluidInTank.getAmount() / fluidTank.getTankCapacity(0);
|
||||
|
||||
boolean reversed = fluidInTank.getFluid()
|
||||
.getFluidType()
|
||||
.isLighterThanAir();
|
||||
if (reversed)
|
||||
level = 1 - level;
|
||||
|
||||
Vec3 vec = ray.getLocation();
|
||||
vec = new Vec3(vec.x, controllerTE.getBlockPos()
|
||||
.getY() + level * (controllerTE.getHeight() - .5f) + .25f, vec.z);
|
||||
Vec3 motion = player.position()
|
||||
.subtract(vec)
|
||||
.scale(1 / 20f);
|
||||
vec = vec.add(motion);
|
||||
world.addParticle(blockParticleData, vec.x, vec.y, vec.z, motion.x, motion.y, motion.z);
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
controllerTE.sendDataImmediately();
|
||||
controllerTE.setChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level world, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
if (state.hasBlockEntity() && (state.getBlock() != newState.getBlock() || !newState.hasBlockEntity())) {
|
||||
BlockEntity te = world.getBlockEntity(pos);
|
||||
if (!(te instanceof FluidTankBlockEntity))
|
||||
return;
|
||||
FluidTankBlockEntity tankTE = (FluidTankBlockEntity) te;
|
||||
world.removeBlockEntity(pos);
|
||||
ConnectivityHandler.splitMulti(tankTE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<FluidTankBlockEntity> getBlockEntityClass() {
|
||||
return FluidTankBlockEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntityType<? extends FluidTankBlockEntity> getBlockEntityType() {
|
||||
return TFMGBlockEntities.TFMG_FLUID_TANK.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState mirror(BlockState state, Mirror mirror) {
|
||||
if (mirror == Mirror.NONE)
|
||||
return state;
|
||||
boolean x = mirror == Mirror.FRONT_BACK;
|
||||
switch (state.getValue(SHAPE)) {
|
||||
case WINDOW_NE:
|
||||
return state.setValue(SHAPE, x ? Shape.WINDOW_NW : Shape.WINDOW_SE);
|
||||
case WINDOW_NW:
|
||||
return state.setValue(SHAPE, x ? Shape.WINDOW_NE : Shape.WINDOW_SW);
|
||||
case WINDOW_SE:
|
||||
return state.setValue(SHAPE, x ? Shape.WINDOW_SW : Shape.WINDOW_NE);
|
||||
case WINDOW_SW:
|
||||
return state.setValue(SHAPE, x ? Shape.WINDOW_SE : Shape.WINDOW_NW);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, Rotation rotation) {
|
||||
for (int i = 0; i < rotation.ordinal(); i++)
|
||||
state = rotateOnce(state);
|
||||
return state;
|
||||
}
|
||||
|
||||
private BlockState rotateOnce(BlockState state) {
|
||||
switch (state.getValue(SHAPE)) {
|
||||
case WINDOW_NE:
|
||||
return state.setValue(SHAPE, Shape.WINDOW_SE);
|
||||
case WINDOW_NW:
|
||||
return state.setValue(SHAPE, Shape.WINDOW_NE);
|
||||
case WINDOW_SE:
|
||||
return state.setValue(SHAPE, Shape.WINDOW_SW);
|
||||
case WINDOW_SW:
|
||||
return state.setValue(SHAPE, Shape.WINDOW_NW);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Tanks are less noisy when placed in batch
|
||||
public static final SoundType SILENCED_METAL =
|
||||
new ForgeSoundType(0.1F, 1.5F, () -> SoundEvents.METAL_BREAK, () -> SoundEvents.METAL_STEP,
|
||||
() -> SoundEvents.METAL_PLACE, () -> SoundEvents.METAL_HIT, () -> SoundEvents.METAL_FALL);
|
||||
|
||||
@Override
|
||||
public SoundType getSoundType(BlockState state, LevelReader world, BlockPos pos, Entity entity) {
|
||||
SoundType soundType = super.getSoundType(state, world, pos, entity);
|
||||
if (entity != null && entity.getPersistentData()
|
||||
.contains("SilenceTankSound"))
|
||||
return SILENCED_METAL;
|
||||
return soundType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAnalogOutputSignal(BlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAnalogOutputSignal(BlockState blockState, Level worldIn, BlockPos pos) {
|
||||
return getBlockEntityOptional(worldIn, pos).map(FluidTankBlockEntity::getControllerBE)
|
||||
.map(te -> ComparatorUtil.fractionToRedstoneLevel(te.getFillState()))
|
||||
.orElse(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.drmangotea.tfmg.content.decoration.tanks.cast_iron;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.simibubi.create.api.connectivity.ConnectivityHandler;
|
||||
import com.simibubi.create.content.fluids.tank.FluidTankBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public class CastIronTankItem extends BlockItem {
|
||||
|
||||
public CastIronTankItem(Block p_i48527_1_, Properties p_i48527_2_) {
|
||||
super(p_i48527_1_, p_i48527_2_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult place(BlockPlaceContext ctx) {
|
||||
InteractionResult initialResult = super.place(ctx);
|
||||
if (!initialResult.consumesAction())
|
||||
return initialResult;
|
||||
tryMultiPlace(ctx);
|
||||
return initialResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean updateCustomBlockEntityTag(BlockPos p_195943_1_, Level p_195943_2_, Player p_195943_3_,
|
||||
ItemStack p_195943_4_, BlockState p_195943_5_) {
|
||||
MinecraftServer minecraftserver = p_195943_2_.getServer();
|
||||
if (minecraftserver == null)
|
||||
return false;
|
||||
CompoundTag nbt = p_195943_4_.getTagElement("BlockEntityTag");
|
||||
if (nbt != null) {
|
||||
nbt.remove("Luminosity");
|
||||
nbt.remove("Size");
|
||||
nbt.remove("Height");
|
||||
nbt.remove("Controller");
|
||||
nbt.remove("LastKnownPos");
|
||||
if (nbt.contains("TankContent")) {
|
||||
FluidStack fluid = FluidStack.loadFluidStackFromNBT(nbt.getCompound("TankContent"));
|
||||
if (!fluid.isEmpty()) {
|
||||
fluid.setAmount(Math.min(FluidTankBlockEntity.getCapacityMultiplier(), fluid.getAmount()));
|
||||
nbt.put("TankContent", fluid.writeToNBT(new CompoundTag()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.updateCustomBlockEntityTag(p_195943_1_, p_195943_2_, p_195943_3_, p_195943_4_, p_195943_5_);
|
||||
}
|
||||
|
||||
private void tryMultiPlace(BlockPlaceContext ctx) {
|
||||
|
||||
Player player = ctx.getPlayer();
|
||||
if (player == null)
|
||||
return;
|
||||
if (player.isShiftKeyDown())
|
||||
return;
|
||||
Direction face = ctx.getClickedFace();
|
||||
if (!face.getAxis()
|
||||
.isVertical())
|
||||
return;
|
||||
ItemStack stack = ctx.getItemInHand();
|
||||
Level world = ctx.getLevel();
|
||||
BlockPos pos = ctx.getClickedPos();
|
||||
BlockPos placedOnPos = pos.relative(face.getOpposite());
|
||||
BlockState placedOnState = world.getBlockState(placedOnPos);
|
||||
|
||||
if (!CastIronTankBlock.isTank(placedOnState))
|
||||
return;
|
||||
|
||||
FluidTankBlockEntity tankAt = ConnectivityHandler.partAt(
|
||||
TFMGBlockEntities.TFMG_FLUID_TANK.get(), world, placedOnPos
|
||||
);
|
||||
if (tankAt == null)
|
||||
return;
|
||||
FluidTankBlockEntity controllerTE = tankAt.getControllerBE();
|
||||
if (controllerTE == null)
|
||||
return;
|
||||
|
||||
int width = controllerTE.getWidth();
|
||||
if (width == 1)
|
||||
return;
|
||||
|
||||
int tanksToPlace = 0;
|
||||
BlockPos startPos = face == Direction.DOWN ? controllerTE.getBlockPos()
|
||||
.below()
|
||||
: controllerTE.getBlockPos()
|
||||
.above(controllerTE.getHeight());
|
||||
|
||||
if (startPos.getY() != pos.getY())
|
||||
return;
|
||||
|
||||
for (int xOffset = 0; xOffset < width; xOffset++) {
|
||||
for (int zOffset = 0; zOffset < width; zOffset++) {
|
||||
BlockPos offsetPos = startPos.offset(xOffset, 0, zOffset);
|
||||
BlockState blockState = world.getBlockState(offsetPos);
|
||||
if (CastIronTankBlock.isTank(blockState))
|
||||
continue;
|
||||
if (!blockState.canBeReplaced())
|
||||
return;
|
||||
tanksToPlace++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!player.isCreative() && stack.getCount() < tanksToPlace)
|
||||
return;
|
||||
|
||||
for (int xOffset = 0; xOffset < width; xOffset++) {
|
||||
for (int zOffset = 0; zOffset < width; zOffset++) {
|
||||
BlockPos offsetPos = startPos.offset(xOffset, 0, zOffset);
|
||||
BlockState blockState = world.getBlockState(offsetPos);
|
||||
if (CastIronTankBlock.isTank(blockState))
|
||||
continue;
|
||||
BlockPlaceContext context = BlockPlaceContext.at(ctx, offsetPos, face);
|
||||
player.getPersistentData()
|
||||
.putBoolean("SilenceTankSound", true);
|
||||
super.place(context);
|
||||
player.getPersistentData()
|
||||
.remove("SilenceTankSound");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.drmangotea.tfmg.content.decoration.tank;
|
||||
package com.drmangotea.tfmg.content.decoration.tanks.steel;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.base.TFMGSpriteShifts;
|
||||
@@ -23,18 +23,18 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class TFMGFluidTankModel extends CTModel {
|
||||
public class SteelFluidTankModel extends CTModel {
|
||||
|
||||
protected static final ModelProperty<CullData> CULL_PROPERTY = new ModelProperty<>();
|
||||
|
||||
public static TFMGFluidTankModel standard(BakedModel originalModel) {
|
||||
return new TFMGFluidTankModel(originalModel, TFMGSpriteShifts.STEEL_FLUID_TANK, TFMGSpriteShifts.STEEL_FLUID_TANK_TOP,
|
||||
public static SteelFluidTankModel standard(BakedModel originalModel) {
|
||||
return new SteelFluidTankModel(originalModel, TFMGSpriteShifts.STEEL_FLUID_TANK, TFMGSpriteShifts.STEEL_FLUID_TANK_TOP,
|
||||
TFMGSpriteShifts.STEEL_FLUID_TANK_INNER);
|
||||
}
|
||||
|
||||
|
||||
private TFMGFluidTankModel(BakedModel originalModel, CTSpriteShiftEntry side, CTSpriteShiftEntry top,
|
||||
CTSpriteShiftEntry inner) {
|
||||
private SteelFluidTankModel(BakedModel originalModel, CTSpriteShiftEntry side, CTSpriteShiftEntry top,
|
||||
CTSpriteShiftEntry inner) {
|
||||
super(originalModel, new FluidTankCTBehaviour(side, top, inner));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.drmangotea.tfmg.content.decoration.tank;
|
||||
package com.drmangotea.tfmg.content.decoration.tanks.steel;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.registry.TFMGPartialModels;
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.drmangotea.tfmg.content.decoration.tank;
|
||||
package com.drmangotea.tfmg.content.decoration.tanks.steel;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.simibubi.create.api.connectivity.ConnectivityHandler;
|
||||
import com.simibubi.create.content.equipment.wrench.IWrenchable;
|
||||
import com.simibubi.create.content.fluids.tank.FluidTankBlock;
|
||||
import com.simibubi.create.content.fluids.transfer.GenericItemEmptying;
|
||||
import com.simibubi.create.content.fluids.transfer.GenericItemFilling;
|
||||
import com.simibubi.create.foundation.block.IBE;
|
||||
@@ -52,17 +53,16 @@ import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
|
||||
import static com.simibubi.create.content.fluids.tank.FluidTankBlock.Shape;
|
||||
|
||||
public class SteelTankBlock extends Block implements IWrenchable, IBE<SteelTankBlockEntity> {
|
||||
public static final BooleanProperty TOP = BooleanProperty.create("top");
|
||||
public static final BooleanProperty BOTTOM = BooleanProperty.create("bottom");
|
||||
public static final EnumProperty<Shape> SHAPE = EnumProperty.create("shape", Shape.class);
|
||||
public static final BooleanProperty TOP = FluidTankBlock.TOP;
|
||||
public static final BooleanProperty BOTTOM = FluidTankBlock.BOTTOM;
|
||||
public static final EnumProperty<Shape> SHAPE = FluidTankBlock.SHAPE;
|
||||
private boolean creative;
|
||||
public static SteelTankBlock regular(Properties p_i48440_1_) {
|
||||
return new SteelTankBlock(p_i48440_1_, false);
|
||||
}
|
||||
public static SteelTankBlock creative(Properties p_i48440_1_) {
|
||||
return new SteelTankBlock(p_i48440_1_, true);
|
||||
}
|
||||
|
||||
protected SteelTankBlock(Properties p_i48440_1_, boolean creative) {
|
||||
super(p_i48440_1_);
|
||||
@@ -293,13 +293,7 @@ public class SteelTankBlock extends Block implements IWrenchable, IBE<SteelTankB
|
||||
}
|
||||
}
|
||||
|
||||
public enum Shape implements StringRepresentable {
|
||||
PLAIN, WINDOW, WINDOW_NW, WINDOW_SW, WINDOW_NE, WINDOW_SE;
|
||||
@Override
|
||||
public String getSerializedName() {
|
||||
return Lang.asId(name());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Tanks are less noisy when placed in batch
|
||||
public static final SoundType SILENCED_METAL =
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.drmangotea.tfmg.content.decoration.tank;
|
||||
package com.drmangotea.tfmg.content.decoration.tanks.steel;
|
||||
|
||||
import com.drmangotea.tfmg.registry.TFMGBlocks;
|
||||
import com.simibubi.create.api.connectivity.ConnectivityHandler;
|
||||
import com.simibubi.create.content.equipment.goggles.IHaveGoggleInformation;
|
||||
import com.simibubi.create.content.fluids.tank.BoilerHeaters;
|
||||
import com.simibubi.create.content.fluids.tank.FluidTankBlock;
|
||||
import com.simibubi.create.content.fluids.tank.FluidTankBlockEntity;
|
||||
import com.simibubi.create.foundation.blockEntity.IMultiBlockEntityContainer;
|
||||
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
|
||||
@@ -216,7 +217,7 @@ public class SteelTankBlockEntity extends FluidTankBlockEntity implements IHaveG
|
||||
if (SteelTankBlock.isTank(state)) {
|
||||
state = state.setValue(SteelTankBlock.BOTTOM, true);
|
||||
state = state.setValue(SteelTankBlock.TOP, true);
|
||||
state = state.setValue(SteelTankBlock.SHAPE, window ? SteelTankBlock.Shape.WINDOW : SteelTankBlock.Shape.PLAIN);
|
||||
state = state.setValue(SteelTankBlock.SHAPE, window ? FluidTankBlock.Shape.WINDOW : FluidTankBlock.Shape.PLAIN);
|
||||
getLevel().setBlock(worldPosition, state, 22);
|
||||
}
|
||||
refreshCapability();
|
||||
@@ -259,18 +260,18 @@ public class SteelTankBlockEntity extends FluidTankBlockEntity implements IHaveG
|
||||
BlockState blockState = level.getBlockState(pos);
|
||||
if (!SteelTankBlock.isTank(blockState))
|
||||
continue;
|
||||
SteelTankBlock.Shape shape = SteelTankBlock.Shape.PLAIN;
|
||||
FluidTankBlock.Shape shape = FluidTankBlock.Shape.PLAIN;
|
||||
if (window) {
|
||||
// SIZE 1: Every tank has a window
|
||||
if (width == 1)
|
||||
shape = SteelTankBlock.Shape.WINDOW;
|
||||
shape = FluidTankBlock.Shape.WINDOW;
|
||||
// SIZE 2: Every tank has a corner window
|
||||
if (width == 2)
|
||||
shape = xOffset == 0 ? zOffset == 0 ? SteelTankBlock.Shape.WINDOW_NW : SteelTankBlock.Shape.WINDOW_SW
|
||||
: zOffset == 0 ? SteelTankBlock.Shape.WINDOW_NE : SteelTankBlock.Shape.WINDOW_SE;
|
||||
shape = xOffset == 0 ? zOffset == 0 ? FluidTankBlock.Shape.WINDOW_NW : FluidTankBlock.Shape.WINDOW_SW
|
||||
: zOffset == 0 ? FluidTankBlock.Shape.WINDOW_NE : FluidTankBlock.Shape.WINDOW_SE;
|
||||
// SIZE 3: Tanks in the center have a window
|
||||
if (width == 3 && abs(abs(xOffset) - abs(zOffset)) == 1)
|
||||
shape = SteelTankBlock.Shape.WINDOW;
|
||||
shape = FluidTankBlock.Shape.WINDOW;
|
||||
}
|
||||
|
||||
level.setBlock(pos, blockState.setValue(SteelTankBlock.SHAPE, shape), 22);
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.drmangotea.tfmg.content.decoration.tank;
|
||||
package com.drmangotea.tfmg.content.decoration.tanks.steel;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.drmangotea.tfmg.content.electricity.base;
|
||||
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.drmangotea.tfmg.content.electricity.lights.LightBulbBlockEntity;
|
||||
import com.drmangotea.tfmg.registry.TFMGPackets;
|
||||
import com.simibubi.create.content.equipment.goggles.IHaveHoveringInformation;
|
||||
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
|
||||
@@ -9,6 +10,7 @@ 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.item.DyeColor;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
@@ -24,14 +26,14 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric,
|
||||
public ElectricBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
data.connectNextTick = true;
|
||||
if(!canBeInGroups()){
|
||||
data.group = new ElectricalGroup(-1);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean addToTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
|
||||
return makeElectricityTooltip(tooltip, isPlayerSneaking);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void addBehaviours(List<BlockEntityBehaviour> behaviours) {}
|
||||
|
||||
@@ -56,6 +58,11 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lazyTick() {
|
||||
super.lazyTick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricBlockValues getData() {
|
||||
return data;
|
||||
@@ -121,10 +128,6 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void updateNextTick() {
|
||||
data.updateNextTick = true;
|
||||
@@ -145,6 +148,11 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric,
|
||||
|
||||
@Override
|
||||
public void setVoltage(int newVoltage) {
|
||||
|
||||
//if(this instanceof LightBulbBlockEntity be&&be.color == DyeColor.WHITE){
|
||||
// TFMG.LOGGER.debug("Rezistancja Grup "+data.group.resistance);
|
||||
//}
|
||||
|
||||
if(canBeInGroups()){
|
||||
data.voltage = (int) (((float)resistance()/data.group.resistance)*(float)data.voltageSupply);
|
||||
return;
|
||||
@@ -205,6 +213,7 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric,
|
||||
.remove(be.getPos());
|
||||
be.setNetwork(be.getPos());
|
||||
be.onPlaced();
|
||||
|
||||
be.updateNextTick();
|
||||
}
|
||||
}
|
||||
@@ -227,19 +236,27 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric,
|
||||
updateNetwork();
|
||||
data.updateNextTick = false;
|
||||
}
|
||||
if(data.setVoltageNextTick) {
|
||||
setVoltage(data.voltageSupply);
|
||||
data.setVoltageNextTick = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void write(CompoundTag tag, boolean clientPacket) {
|
||||
super.write(tag, clientPacket);
|
||||
protected void write(CompoundTag compound, boolean clientPacket) {
|
||||
super.write(compound, clientPacket);
|
||||
|
||||
compound.putInt("GroupId", data.group.id);
|
||||
compound.putFloat("GroupResistance", data.group.resistance);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void read(CompoundTag tag, boolean clientPacket) {
|
||||
super.read(tag, clientPacket);
|
||||
protected void read(CompoundTag compound, boolean clientPacket) {
|
||||
super.read(compound, clientPacket);
|
||||
data.group = new ElectricalGroup(compound.getInt("GroupId"));
|
||||
data.group.resistance = compound.getFloat("GroupResistance");
|
||||
if(!clientPacket)
|
||||
data.connectNextTick = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ public class ElectricBlockValues {
|
||||
public int frequency = 0;
|
||||
public int voltageSupply = 0;
|
||||
public int networkPowerGeneration =0;
|
||||
public float highestCurrent=0;
|
||||
|
||||
public boolean setVoltageNextTick = false;
|
||||
|
||||
public ElectricalGroup group = new ElectricalGroup(0);
|
||||
|
||||
@@ -29,6 +32,4 @@ public class ElectricBlockValues {
|
||||
public int getVoltage(){
|
||||
return voltage;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.drmangotea.tfmg.content.electricity.base;
|
||||
|
||||
import com.drmangotea.tfmg.content.electricity.connection.cables.IHaveCables;
|
||||
import com.drmangotea.tfmg.content.electricity.connection.cables.WireNetwork;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import org.apache.http.impl.conn.Wire;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -11,11 +14,9 @@ public class ElectricNetworkManager {
|
||||
|
||||
public void onLoadWorld(LevelAccessor world) {
|
||||
networks.put(world, new HashMap<>());
|
||||
|
||||
}
|
||||
public void onUnloadWorld(LevelAccessor world) {
|
||||
networks.remove(world);
|
||||
|
||||
}
|
||||
public ElectricalNetwork getOrCreateNetworkFor(IElectric be) {
|
||||
Long id = be.getData().getId();
|
||||
@@ -26,7 +27,7 @@ public class ElectricNetworkManager {
|
||||
network = new ElectricalNetwork(id);
|
||||
|
||||
if(be instanceof IElectric) {
|
||||
network.add((IElectric) be);
|
||||
network.add(be);
|
||||
be.setNetwork(be.getData().getId());
|
||||
}
|
||||
map.put(id, network);
|
||||
@@ -34,5 +35,4 @@ public class ElectricNetworkManager {
|
||||
network = map.get(id);
|
||||
return network;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.drmangotea.tfmg.content.electricity.base;
|
||||
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.drmangotea.tfmg.content.electricity.lights.LightBulbBlockEntity;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -52,7 +54,8 @@ public class ElectricalNetwork {
|
||||
resistance += (int) member.resistance();
|
||||
powerGeneration += member.powerGeneration();
|
||||
if(member.canBeInGroups())
|
||||
groups.put(groupId, (groups.containsKey(groupId) ? groups.get(groupId) + member.resistance() : member.resistance()));
|
||||
groups.put(groupId, groups.containsKey(groupId) ? groups.get(groupId) + member.resistance() : member.resistance());
|
||||
|
||||
}
|
||||
|
||||
int powerPercentage = resistance > 0 ? (int) (Math.min(((float) power / (float) resistance * 100f), 100)) : 100;
|
||||
@@ -61,20 +64,45 @@ public class ElectricalNetwork {
|
||||
|
||||
int oldVoltage = member.getData().getVoltage();
|
||||
int oldPower = member.getPowerUsage();
|
||||
|
||||
member.setVoltage(maxVoltage);
|
||||
member.getData().voltageSupply = maxVoltage;
|
||||
member.setVoltage(maxVoltage);
|
||||
member.getData().setVoltageNextTick = true;
|
||||
|
||||
member.getData().networkPowerGeneration = powerGeneration;
|
||||
member.setWattage(power);
|
||||
member.setFrequency(frequency);
|
||||
member.setNetworkResistance(resistance);
|
||||
member.onNetworkChanged(oldVoltage, oldPower);
|
||||
member.setPowerPercentage(powerPercentage);
|
||||
member.updateNearbyNetworks(member);
|
||||
|
||||
|
||||
if(groups.containsKey(member.getData().group.id))
|
||||
member.getData().group.resistance = groups.get(member.getData().group.id);
|
||||
}
|
||||
for (IElectric member : members) {
|
||||
member.getData().highestCurrent = getCableCurrent(member);
|
||||
member.updateNearbyNetworks(member);
|
||||
}
|
||||
|
||||
}
|
||||
public static float getCableCurrent(IElectric be){
|
||||
|
||||
float current =0;
|
||||
List<Integer> groups = new ArrayList<>();
|
||||
|
||||
for(IElectric member : be.getOrCreateElectricNetwork().members){
|
||||
|
||||
if(member.canBeInGroups())
|
||||
if(!groups.contains(member.getData().group.id)){
|
||||
groups.add(member.getData().group.id);
|
||||
if(member.resistance()!=0)
|
||||
|
||||
current += member.getData().voltage/member.resistance();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
public List<IElectric> getMembers() {
|
||||
|
||||
@@ -11,20 +11,25 @@ import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface IElectric {
|
||||
long getPos();
|
||||
|
||||
LevelAccessor getLevelAccessor();
|
||||
|
||||
boolean destroyed();
|
||||
|
||||
ElectricalNetwork getOrCreateElectricNetwork();
|
||||
default boolean hasElectricitySlot(Direction direction){
|
||||
|
||||
default boolean hasElectricitySlot(Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
default void onPlaced(){
|
||||
if(!getLevelAccessor().isClientSide())
|
||||
default void onPlaced() {
|
||||
if (!getLevelAccessor().isClientSide())
|
||||
TFMGPackets.getChannel().send(PacketDistributor.ALL.noArg(), new ConnectNeightborsPacket(BlockPos.of(getPos())));
|
||||
TFMG.NETWORK_MANAGER.getOrCreateNetworkFor(this);
|
||||
setNetwork(getPos());
|
||||
@@ -33,14 +38,15 @@ public interface IElectric {
|
||||
sendStuff();
|
||||
updateNextTick();
|
||||
}
|
||||
default void onConnected(){
|
||||
|
||||
default void onConnected() {
|
||||
|
||||
|
||||
BlockPos pos = BlockPos.of(getPos());
|
||||
for(Direction d : Direction.values()){
|
||||
if(hasElectricitySlot(d))
|
||||
if(getLevelAccessor().getBlockEntity(pos.relative(d)) instanceof IElectric be){
|
||||
if(be.hasElectricitySlot(d.getOpposite())) {
|
||||
for (Direction d : Direction.values()) {
|
||||
if (hasElectricitySlot(d))
|
||||
if (getLevelAccessor().getBlockEntity(pos.relative(d)) instanceof IElectric be) {
|
||||
if (be.hasElectricitySlot(d.getOpposite())) {
|
||||
if (!be.destroyed()) {
|
||||
getOrCreateElectricNetwork().add(be);
|
||||
if (be.getData().getId() != getData().getId()) {
|
||||
@@ -50,7 +56,7 @@ public interface IElectric {
|
||||
sendStuff();
|
||||
}
|
||||
}
|
||||
} else if(be.getData().getId()!=getData().getId()){
|
||||
} else if (be.getData().getId() != getData().getId()) {
|
||||
be.updateNextTick();
|
||||
}
|
||||
}
|
||||
@@ -59,44 +65,47 @@ public interface IElectric {
|
||||
}
|
||||
|
||||
|
||||
default boolean makeElectricityTooltip(List<Component> tooltip, boolean isPlayerSneaking){
|
||||
default boolean makeElectricityTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
|
||||
|
||||
|
||||
Lang.translate("multimeter.header")
|
||||
.style(ChatFormatting.WHITE)
|
||||
.forGoggles(tooltip, 1);
|
||||
Lang.text(" R = "+TFMGUtils.formatUnits(voltageGeneration()>0 ? getGeneratorResistance() : resistance(), "Ω"))
|
||||
Lang.text(" R = " + TFMGUtils.formatUnits(voltageGeneration() > 0 ? getGeneratorResistance() : resistance(), "Ω"))
|
||||
.style(ChatFormatting.GOLD)
|
||||
.forGoggles(tooltip, 1);
|
||||
Lang.text(" P = "+TFMGUtils.formatUnits(getPowerUsage(), "W"))
|
||||
Lang.text(" P = " + TFMGUtils.formatUnits(getPowerUsage(), "W"))
|
||||
.style(ChatFormatting.GOLD)
|
||||
.forGoggles(tooltip, 1);
|
||||
Lang.text(" U = "+TFMGUtils.formatUnits(getData().getVoltage(), "V"))
|
||||
Lang.text(" U = " + TFMGUtils.formatUnits(getData().getVoltage(), "V"))
|
||||
.style(ChatFormatting.AQUA)
|
||||
.forGoggles(tooltip, 1);
|
||||
Lang.text(" I = "+TFMGUtils.formatUnits(getCurrent(), "A"))
|
||||
Lang.text(" I = " + TFMGUtils.formatUnits(getCurrent(), "A"))
|
||||
.style(ChatFormatting.GREEN)
|
||||
.forGoggles(tooltip, 1);
|
||||
|
||||
////////
|
||||
Lang.text(" Network Resistance: "+TFMGUtils.formatUnits(getNetworkResistance(), "Ω"))
|
||||
Lang.text(" Network Resistance: " + TFMGUtils.formatUnits(getNetworkResistance(), "Ω"))
|
||||
.style(ChatFormatting.YELLOW)
|
||||
.forGoggles(tooltip, 1);
|
||||
Lang.text(" Network Power Usage: "+TFMGUtils.formatUnits(getNetworkPowerUsage(), "W"))
|
||||
Lang.text(" Max Current: " + TFMGUtils.formatUnits(getData().highestCurrent, "A"))
|
||||
.style(ChatFormatting.AQUA)
|
||||
.forGoggles(tooltip, 1);
|
||||
Lang.text(" Network Power Usage: " + TFMGUtils.formatUnits(getNetworkPowerUsage(), "W"))
|
||||
.style(ChatFormatting.YELLOW)
|
||||
.forGoggles(tooltip, 1);
|
||||
Lang.text(" Group: "+getData().group.id)
|
||||
Lang.text(" Group: " + getData().group.id)
|
||||
.style(ChatFormatting.DARK_PURPLE)
|
||||
.forGoggles(tooltip, 1);
|
||||
Lang.text(" Group Resistance: "+getData().group.resistance)
|
||||
Lang.text(" Group Resistance: " + getData().group.resistance)
|
||||
.style(ChatFormatting.DARK_PURPLE)
|
||||
.forGoggles(tooltip, 1);
|
||||
Lang.text(" Voltage Supply: "+getData().voltageSupply)
|
||||
Lang.text(" Voltage Supply: " + getData().voltageSupply)
|
||||
.style(ChatFormatting.DARK_PURPLE)
|
||||
.forGoggles(tooltip, 1);
|
||||
|
||||
|
||||
if(voltageGeneration() > 0) {
|
||||
if (voltageGeneration() > 0) {
|
||||
Lang.translate("multimeter.power_generated")
|
||||
.add(Component.literal(TFMGUtils.formatUnits(powerGeneration(), "W")))
|
||||
.style(ChatFormatting.BLUE)
|
||||
@@ -111,60 +120,98 @@ public interface IElectric {
|
||||
return true;
|
||||
}
|
||||
|
||||
default void updateNearbyNetworks(IElectric member){
|
||||
if(member.getData().getsOutsidePower)
|
||||
for(Direction direction : Direction.values()){
|
||||
if(member.getLevelAccessor().getBlockEntity(BlockPos.of(member.getPos()).relative(direction)) instanceof IElectric be&&be.getData().getId()!=be.getData().getId()){
|
||||
default void updateNearbyNetworks(IElectric member) {
|
||||
if (member.getData().getsOutsidePower)
|
||||
for (Direction direction : Direction.values()) {
|
||||
if (member.getLevelAccessor().getBlockEntity(BlockPos.of(member.getPos()).relative(direction)) instanceof IElectric be && be.getData().getId() != be.getData().getId()) {
|
||||
be.updateNextTick();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ElectricBlockValues getData();
|
||||
default int getPowerUsage(){
|
||||
return (int) (getData().getVoltage()*getCurrent());
|
||||
default boolean isCable() {
|
||||
return false;
|
||||
}
|
||||
default int getNetworkPowerUsage(){
|
||||
int power=0;
|
||||
for(IElectric member : getOrCreateElectricNetwork().members)
|
||||
power+=member.getPowerUsage();
|
||||
|
||||
ElectricBlockValues getData();
|
||||
|
||||
default int getPowerUsage() {
|
||||
return (int) (getData().getVoltage() * getCurrent());
|
||||
}
|
||||
|
||||
default int getNetworkPowerUsage() {
|
||||
int power = 0;
|
||||
for (IElectric member : getOrCreateElectricNetwork().members)
|
||||
power += member.getPowerUsage();
|
||||
return power;
|
||||
}
|
||||
default void onNetworkChanged(int oldVoltage, int oldPower){}
|
||||
|
||||
default float getGeneratorResistance(){
|
||||
if(getData().voltageSupply == 0)
|
||||
return 0;
|
||||
return (float) powerGeneration() / (float)getData().networkPowerGeneration *(float)getNetworkResistance();
|
||||
default void onNetworkChanged(int oldVoltage, int oldPower) {
|
||||
}
|
||||
default float getGeneratorLoad(){
|
||||
if(getNetworkPowerUsage() == 0)
|
||||
|
||||
default float getGeneratorResistance() {
|
||||
if (getData().voltageSupply == 0)
|
||||
return 0;
|
||||
return (float) powerGeneration() / (float)getData().networkPowerGeneration *getNetworkPowerUsage();
|
||||
return (float) powerGeneration() / (float) getData().networkPowerGeneration * (float) getNetworkResistance();
|
||||
}
|
||||
|
||||
default float getGeneratorLoad() {
|
||||
if (getNetworkPowerUsage() == 0)
|
||||
return 0;
|
||||
return (float) powerGeneration() / (float) getData().networkPowerGeneration * getNetworkPowerUsage();
|
||||
}
|
||||
|
||||
int getPowerPercentage();
|
||||
|
||||
float resistance();
|
||||
|
||||
int voltageGeneration();
|
||||
|
||||
int powerGeneration();
|
||||
|
||||
int frequencyGeneration();
|
||||
|
||||
int getNetworkResistance();
|
||||
default int getMaxAmps(){
|
||||
|
||||
default int getMaxAmps() {
|
||||
return (int) getCurrent();
|
||||
}
|
||||
default float getCurrent(){
|
||||
return getData().getVoltage()==0||resistance() == 0 ? 0 : ((float) getData().getVoltage() / (float) resistance());
|
||||
|
||||
default float getCurrent() {
|
||||
return getData().getVoltage() == 0 || resistance() == 0 ? 0 : ((float) getData().getVoltage() / (float) resistance());
|
||||
}
|
||||
default float getCableCurrent(){
|
||||
float current =0;
|
||||
List<Integer> groups = new ArrayList<>();
|
||||
for(IElectric member : getOrCreateElectricNetwork().members){
|
||||
if(member.canBeInGroups())
|
||||
if(!groups.contains(member.getData().group.id)){
|
||||
current+=member.getCurrent();
|
||||
groups.add(member.getData().group.id);
|
||||
}
|
||||
}
|
||||
return current;
|
||||
}
|
||||
void updateNextTick();
|
||||
|
||||
void updateNetwork();
|
||||
|
||||
void sendStuff();
|
||||
|
||||
void setVoltage(int newVoltage);
|
||||
|
||||
void setFrequency(int newFrequency);
|
||||
|
||||
void setNetworkResistance(int newUsage);
|
||||
|
||||
void setWattage(int newWattage);
|
||||
|
||||
void setPowerPercentage(int percentage);
|
||||
|
||||
void setNetwork(long network);
|
||||
default boolean canBeInGroups(){
|
||||
|
||||
default boolean canBeInGroups() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.drmangotea.tfmg.content.electricity.connection.cable_hub;
|
||||
|
||||
import com.drmangotea.tfmg.content.electricity.base.ElectricBlockEntity;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.simibubi.create.foundation.block.IBE;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class CableHubBlock extends Block implements IBE<CableHubBlockEntity> {
|
||||
public CableHubBlock(Properties p_49795_) {
|
||||
super(p_49795_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlace(BlockState pState, Level level, BlockPos pos, BlockState pOldState, boolean pIsMoving) {
|
||||
withBlockEntityDo(level,pos, IElectric::onPlaced);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
}
|
||||
@Override
|
||||
public Class<CableHubBlockEntity> getBlockEntityClass() {
|
||||
return CableHubBlockEntity.class;
|
||||
}
|
||||
@Override
|
||||
public BlockEntityType<? extends CableHubBlockEntity> getBlockEntityType() {
|
||||
return TFMGBlockEntities.CABLE_HUB.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.drmangotea.tfmg.content.electricity.connection.cable_hub;
|
||||
|
||||
import com.drmangotea.tfmg.content.electricity.base.ElectricBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class CableHubBlockEntity extends ElectricBlockEntity {
|
||||
public CableHubBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.drmangotea.tfmg.content.electricity.connection.cables;
|
||||
|
||||
import com.drmangotea.tfmg.base.TFMGUtils;
|
||||
import com.drmangotea.tfmg.registry.TFMGItems;
|
||||
import com.tterrag.registrate.util.entry.ItemEntry;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Items;
|
||||
import org.checkerframework.checker.units.qual.C;
|
||||
|
||||
public class CableConnection {
|
||||
|
||||
final CablePos pos1;
|
||||
final CablePos pos2;
|
||||
final BlockPos blockPos1;
|
||||
final BlockPos blockPos2;
|
||||
final boolean visible;
|
||||
final CableType type;
|
||||
|
||||
public CableConnection(CablePos pos1, CablePos pos2,BlockPos blockPos1,BlockPos blockPos2,CableType type, boolean visible){
|
||||
this.pos1 = pos1;
|
||||
this.pos2 = pos2;
|
||||
this.blockPos1 = blockPos1;
|
||||
this.blockPos2 = blockPos2;
|
||||
this.visible = visible;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public CompoundTag saveConnection(){
|
||||
CompoundTag compoundTag = new CompoundTag();
|
||||
|
||||
compoundTag.putDouble("X1", pos1.x());
|
||||
compoundTag.putDouble("Y1", pos1.y());
|
||||
compoundTag.putDouble("Z1", pos1.z());
|
||||
|
||||
compoundTag.putDouble("X2", pos2.x());
|
||||
compoundTag.putDouble("Y2", pos2.y());
|
||||
compoundTag.putDouble("Z2", pos2.z());
|
||||
|
||||
//compoundTag.putLong("BlockPos1", blockPos1.asLong());
|
||||
//compoundTag.putLong("BlockPos2", blockPos2.asLong());
|
||||
|
||||
compoundTag.putInt("XX1", blockPos1.getX());
|
||||
compoundTag.putInt("YY1", blockPos1.getY());
|
||||
compoundTag.putInt("ZZ1", blockPos1.getZ());
|
||||
|
||||
compoundTag.putInt("XX2", blockPos2.getX());
|
||||
compoundTag.putInt("YY2", blockPos2.getY());
|
||||
compoundTag.putInt("ZZ2", blockPos2.getZ());
|
||||
|
||||
|
||||
compoundTag.putBoolean("Visible", visible);
|
||||
|
||||
compoundTag.putString("CableType", type.toString());
|
||||
|
||||
return compoundTag;
|
||||
}
|
||||
public static CableConnection loadConnection(CompoundTag compoundTag){
|
||||
|
||||
|
||||
|
||||
CablePos pos1 = new CablePos(compoundTag.getDouble("X1"),compoundTag.getDouble("Y1"),compoundTag.getDouble("Z1"));
|
||||
CablePos pos2 = new CablePos(compoundTag.getDouble("X2"),compoundTag.getDouble("Y2"),compoundTag.getDouble("Z2"));
|
||||
|
||||
//BlockPos blockPos1 = BlockPos.of(compoundTag.getLong("BlockPos1"));
|
||||
//BlockPos blockPos2 = BlockPos.of(compoundTag.getLong("BlockPos2"));
|
||||
|
||||
BlockPos blockPos1 = new BlockPos(compoundTag.getInt("XX1"),compoundTag.getInt("YY1"),compoundTag.getInt("ZZ1"));
|
||||
BlockPos blockPos2 = new BlockPos(compoundTag.getInt("XX2"),compoundTag.getInt("YY2"),compoundTag.getInt("ZZ2"));
|
||||
|
||||
boolean visible = compoundTag.getBoolean("Visible");
|
||||
CableType type = CableType.valueOf(compoundTag.getString("CableType"));
|
||||
|
||||
return new CableConnection(pos1,pos2,blockPos1,blockPos2,type,visible);
|
||||
}
|
||||
public float getLength(){
|
||||
return TFMGUtils.getDistance(new BlockPos((int) pos1.x(), (int) pos1.y(), (int) pos1.z()),new BlockPos((int) pos2.x(), (int) pos2.y(), (int) pos2.z()), false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public enum CableType{
|
||||
NONE(TFMGItems.COPPER_WIRE, 0,0xffffff),
|
||||
COPPER(TFMGItems.COPPER_WIRE, 0.0188f,0xD8735A),
|
||||
ALUMINUM(TFMGItems.ALUMINUM_WIRE, 0.0188f,0xEDEFEF),
|
||||
STEEL_REINFORCED_ALUMINUM(TFMGItems.COPPER_WIRE, 0.0188f,0x595E5F)
|
||||
;
|
||||
public final ItemEntry<?> wire;
|
||||
public final float resistivity;
|
||||
public final int color;
|
||||
CableType(ItemEntry<?> wire, float resistivity, int color){
|
||||
this.wire = wire;
|
||||
this.resistivity = resistivity;
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package com.drmangotea.tfmg.content.electricity.connection.cables;
|
||||
|
||||
import com.drmangotea.tfmg.base.TFMGShapes;
|
||||
import com.drmangotea.tfmg.base.WallMountBlock;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.simibubi.create.foundation.block.IBE;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
public class CableConnectorBlock extends WallMountBlock implements IBE<CableConnectorBlockEntity>, IHaveCables {
|
||||
|
||||
public static final BooleanProperty EXTENSION = BooleanProperty.create("extension");
|
||||
|
||||
|
||||
public CableConnectorBlock(Properties p_49795_) {
|
||||
super(p_49795_);
|
||||
this.registerDefaultState(this.getStateDefinition().any().setValue(EXTENSION, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlace(BlockState state, Level level, BlockPos pos, BlockState blockState1, boolean b) {
|
||||
updateExtension(level,state,pos);
|
||||
|
||||
BlockPos below = pos.relative(state.getValue(FACING).getOpposite());
|
||||
BlockState stateBelow = level.getBlockState(below);
|
||||
if(stateBelow.getBlock() instanceof IHaveCables)
|
||||
updateExtension(level,stateBelow,below);
|
||||
|
||||
super.onPlace(state, level, pos, blockState1, b);
|
||||
}
|
||||
|
||||
//@Override
|
||||
//public InteractionResult use(BlockState state, Level level, BlockPos pos, Player p_60506_, InteractionHand p_60507_, BlockHitResult p_60508_) {
|
||||
// if(level.isClientSide)
|
||||
// return InteractionResult.SUCCESS;
|
||||
// if(level.getBlockEntity(pos) instanceof CableConnectorBlockEntity be&&p_60506_.isCrouching()){
|
||||
//
|
||||
//
|
||||
// Direction direction = Direction.NORTH;
|
||||
//
|
||||
//
|
||||
//
|
||||
// int numero = Create.RANDOM.nextInt(6);
|
||||
// if(numero == 0)
|
||||
// direction = Direction.NORTH;
|
||||
//
|
||||
// if(numero == 1)
|
||||
// direction = Direction.SOUTH;
|
||||
// if(numero == 2)
|
||||
// direction = Direction.WEST;
|
||||
// if(numero == 3)
|
||||
// direction = Direction.EAST;
|
||||
// if(numero == 4)
|
||||
// direction = Direction.UP;
|
||||
// if(numero == 5)
|
||||
// direction = Direction.DOWN;
|
||||
//
|
||||
// be.addConnection(pos.relative(direction));
|
||||
// return InteractionResult.SUCCESS;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// return InteractionResult.SUCCESS;
|
||||
//}
|
||||
//@Override
|
||||
//public void onRemove(BlockState state, Level level, BlockPos pos, BlockState blockState1, boolean b) {
|
||||
// updateExtension(level,state,pos);
|
||||
// super.onRemove(state, level, pos, blockState1, b);
|
||||
//}
|
||||
|
||||
@Override
|
||||
public void onNeighborChange(BlockState state, LevelReader level, BlockPos pos, BlockPos neighbor) {
|
||||
|
||||
|
||||
updateExtension((Level) level,state,pos);
|
||||
|
||||
super.onNeighborChange(state, level, pos, neighbor);
|
||||
}
|
||||
|
||||
public void updateExtension(Level level, BlockState state, BlockPos pos){
|
||||
BlockPos above = pos.relative(state.getValue(FACING));
|
||||
BlockState stateAbove = level.getBlockState(above);
|
||||
|
||||
if(stateAbove.getBlock() instanceof IHaveCables) {
|
||||
level.setBlockAndUpdate(pos, state.setValue(EXTENSION, true));
|
||||
} else {
|
||||
level.setBlockAndUpdate(pos, state.setValue(EXTENSION, false));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||
super.createBlockStateDefinition(builder);
|
||||
builder.add(EXTENSION);
|
||||
}
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState pState, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
|
||||
if(pState.getValue(EXTENSION))
|
||||
return TFMGShapes.CABLE_CONNECTOR_MIDDLE.get(pState.getValue(FACING));
|
||||
|
||||
|
||||
return TFMGShapes.CABLE_CONNECTOR.get(pState.getValue(FACING));
|
||||
|
||||
}
|
||||
@Override
|
||||
public Class<CableConnectorBlockEntity> getBlockEntityClass() {
|
||||
return CableConnectorBlockEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntityType<? extends CableConnectorBlockEntity> getBlockEntityType() {
|
||||
return TFMGBlockEntities.CABLE_CONNECTOR.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package com.drmangotea.tfmg.content.electricity.connection.cables;
|
||||
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.drmangotea.tfmg.content.electricity.base.ElectricNetworkManager;
|
||||
import com.drmangotea.tfmg.registry.TFMGPackets;
|
||||
import com.simibubi.create.content.equipment.goggles.IHaveHoveringInformation;
|
||||
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
|
||||
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
import com.simibubi.create.foundation.utility.animation.LerpedFloat;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CableConnectorBlockEntity extends SmartBlockEntity implements IHaveHoveringInformation {
|
||||
|
||||
//player held cable rendering
|
||||
public Player player;
|
||||
public int color = 0x000000;
|
||||
public LerpedFloat wireMovementX = LerpedFloat.linear();
|
||||
public LerpedFloat wireMovementY = LerpedFloat.linear();
|
||||
public LerpedFloat wireMovementZ = LerpedFloat.linear();
|
||||
//
|
||||
|
||||
public List<CableConnection> connections = new ArrayList<>();
|
||||
public long id;
|
||||
|
||||
public CableConnectorBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
wireMovementX.setValue(pos.getX());
|
||||
wireMovementY.setValue(pos.getY());
|
||||
wireMovementZ.setValue(pos.getZ());
|
||||
id = getBlockPos().asLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBehaviours(List<BlockEntityBehaviour> behaviours) {}
|
||||
@Override
|
||||
public void remove() {
|
||||
super.remove();
|
||||
removeConnections(false);
|
||||
}
|
||||
|
||||
public void removeConnections(boolean client) {
|
||||
if (!level.isClientSide()) {
|
||||
TFMGPackets.getChannel().send(PacketDistributor.ALL.noArg(), new CablePacket(this.getBlockPos()));
|
||||
} else if(!client)
|
||||
return;
|
||||
|
||||
for (CableConnection connection : connections) {
|
||||
ItemEntity itemToDrop = new ItemEntity(level, getBlockPos().getX() + 0.5f, getBlockPos().getY() + 0.5f, getBlockPos().getZ() + 0.5f, new ItemStack(connection.type.wire.get(), (int) (connection.getLength())));
|
||||
if (itemToDrop.getItem().getCount() > 0) {
|
||||
level.addFreshEntity(itemToDrop);
|
||||
}
|
||||
BlockPos pos = connection.blockPos1 == getBlockPos() ? connection.blockPos2 : connection.blockPos1;
|
||||
if (level.getBlockEntity(pos) instanceof CableConnectorBlockEntity be) {
|
||||
|
||||
if(be.getBlockPos() == getBlockPos())
|
||||
continue;
|
||||
be.connections.removeIf(c->c.blockPos1==getBlockPos()||c.blockPos2==getBlockPos());
|
||||
be.setChanged();
|
||||
be.sendData();
|
||||
setChanged();
|
||||
sendData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (player != null)
|
||||
managePlayerWire();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void write(CompoundTag compound, boolean clientPacket) {
|
||||
super.write(compound, clientPacket);
|
||||
|
||||
compound.putInt("ConnectionCount", connections.size());
|
||||
|
||||
for (int i = 0; i < connections.size(); i++) {
|
||||
CableConnection connection = connections.get(i);
|
||||
compound.put("Connection" + i, connection.saveConnection());
|
||||
//
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lazyTick() {
|
||||
super.lazyTick();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void read(CompoundTag compound, boolean clientPacket) {
|
||||
super.read(compound, clientPacket);
|
||||
connections = new ArrayList<>();
|
||||
for (int i = 0; i < compound.getInt("ConnectionCount"); i++) {
|
||||
|
||||
connections.add(CableConnection.loadConnection(compound.getCompound("Connection" + i)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void managePlayerWire() {
|
||||
wireMovementX.chase(player.getX() - .5, 0.7, LerpedFloat.Chaser.EXP);
|
||||
wireMovementY.chase(player.getY() + (player.isCrouching() ? 0.6 : 0.9), 0.3, LerpedFloat.Chaser.EXP);
|
||||
wireMovementZ.chase(player.getZ() - .5, 0.7, LerpedFloat.Chaser.EXP);
|
||||
wireMovementX.tickChaser();
|
||||
wireMovementY.tickChaser();
|
||||
wireMovementZ.tickChaser();
|
||||
}
|
||||
|
||||
public CablePos getCablePosition() {
|
||||
return new CablePos(getBlockPos().getX(), getBlockPos().getY(), getBlockPos().getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getRenderBoundingBox() {
|
||||
return new AABB(getBlockPos()).inflate(30);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.drmangotea.tfmg.content.electricity.connection.cables;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.base.WallMountBlock;
|
||||
import com.simibubi.create.foundation.data.AssetLookup;
|
||||
import com.simibubi.create.foundation.data.SpecialBlockStateGen;
|
||||
import com.tterrag.registrate.providers.DataGenContext;
|
||||
import com.tterrag.registrate.providers.RegistrateBlockstateProvider;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.client.model.generators.ModelFile;
|
||||
|
||||
public class CableConnectorGenerator extends SpecialBlockStateGen {
|
||||
public CableConnectorGenerator() {
|
||||
}
|
||||
|
||||
protected int getXRotation(BlockState state) {
|
||||
short value;
|
||||
switch ((Direction)state.getValue(WallMountBlock.FACING)) {
|
||||
case NORTH:
|
||||
value = 90;
|
||||
break;
|
||||
case SOUTH:
|
||||
value = 90;
|
||||
break;
|
||||
case WEST:
|
||||
value = 90;
|
||||
break;
|
||||
case EAST:
|
||||
value = 90;
|
||||
break;
|
||||
case DOWN:
|
||||
value = 180;
|
||||
break;
|
||||
case UP:
|
||||
value = 0;
|
||||
break;
|
||||
default:
|
||||
throw new IncompatibleClassChangeError();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
protected int getYRotation(BlockState state) {
|
||||
short value;
|
||||
switch ((Direction)state.getValue(WallMountBlock.FACING)) {
|
||||
case NORTH:
|
||||
value = 0;
|
||||
break;
|
||||
case SOUTH:
|
||||
value = 180;
|
||||
break;
|
||||
case WEST:
|
||||
value = 270;
|
||||
break;
|
||||
case EAST:
|
||||
value = 90;
|
||||
break;
|
||||
case DOWN:
|
||||
value = 0;
|
||||
break;
|
||||
case UP:
|
||||
value = 0;
|
||||
break;
|
||||
default:
|
||||
throw new IncompatibleClassChangeError();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public <T extends Block> ModelFile getModel(DataGenContext<Block, T> ctx, RegistrateBlockstateProvider prov, BlockState state) {
|
||||
return (Boolean)state.getValue(CableConnectorBlock.EXTENSION) ? AssetLookup.partialBaseModel(ctx, prov, new String[]{"extension"}) : AssetLookup.partialBaseModel(ctx, prov, new String[0]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.drmangotea.tfmg.content.electricity.connection.cables;
|
||||
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.drmangotea.tfmg.base.TFMGUtils;
|
||||
import com.drmangotea.tfmg.content.machinery.misc.winding_machine.SpoolItem;
|
||||
import com.drmangotea.tfmg.registry.TFMGTags;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.simibubi.create.foundation.blockEntity.renderer.SafeBlockEntityRenderer;
|
||||
import com.simibubi.create.foundation.utility.Pair;
|
||||
import com.simibubi.create.foundation.utility.animation.LerpedFloat;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class CableConnectorRenderer extends SafeBlockEntityRenderer<CableConnectorBlockEntity> {
|
||||
|
||||
|
||||
public CableConnectorRenderer(BlockEntityRendererProvider.Context context) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderSafe(CableConnectorBlockEntity be, float partialTicks, PoseStack ms, MultiBufferSource bufferSource, int light, int overlay) {
|
||||
renderPlayerHeldCable(be, ms, bufferSource, partialTicks);
|
||||
|
||||
for (CableConnection connection : be.connections) {
|
||||
if (connection.visible)
|
||||
TFMGUtils.renderWire(be.getLevel(), ms, bufferSource, connection.pos1, connection.pos2, connection.getLength() / 4500, new Color(connection.type.color).getRed(), new Color(connection.type.color).getGreen(), new Color(connection.type.color).getBlue());
|
||||
}
|
||||
|
||||
//for (BlockPos connection : be.connections) {
|
||||
//
|
||||
// BlockPos pos = connection;
|
||||
// // if (connection.visible)
|
||||
// TFMGUtils.renderWire(be.getLevel(), ms, bufferSource, new CablePos(pos.getX(),pos.getY(),pos.getZ()), be.getCablePosition(), 0, new Color(CableConnection.CableType.COPPER.color).getRed(), new Color(CableConnection.CableType.COPPER.color).getGreen(), new Color(CableConnection.CableType.COPPER.color).getBlue());
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
public void renderPlayerHeldCable(CableConnectorBlockEntity be, PoseStack ms, MultiBufferSource bufferSource, float partialTicks) {
|
||||
if (be.player == null)
|
||||
return;
|
||||
Player player = be.player;
|
||||
if (player.getInventory().contains(TFMGTags.TFMGItemTags.SPOOLS.tag)) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.getOrCreateTag().getLong("Position") != 0) {
|
||||
|
||||
CablePos position = new CablePos(stack.getOrCreateTag().getDouble("XPos"), stack.getOrCreateTag().getDouble("YPos"), stack.getOrCreateTag().getDouble("ZPos"));
|
||||
BlockPos pos = BlockPos.of(stack.getOrCreateTag().getLong("Position"));
|
||||
|
||||
if (pos.equals(be.getBlockPos()))
|
||||
TFMGUtils.renderWire(be.getLevel(), ms, bufferSource, new CablePos(be.wireMovementX.getValue(partialTicks), be.wireMovementY.getValue(partialTicks), be.wireMovementZ.getValue(partialTicks)), position, 0.0001f, new Color(be.color).getRed(), new Color(be.color).getGreen(), new Color(be.color).getBlue());
|
||||
// TFMGUtils.renderWire(be.getLevel(), ms, bufferSource, new CablePos(be.player.getX(), be.player.getY(), be.player.getZ()), position, 0.0001f, new Color(be.color).getRed(), new Color(be.color).getGreen(), new Color(be.color).getBlue());
|
||||
//TFMGUtils.renderWire(be.getLevel(), ms, bufferSource, position, new CablePos(be.player.getX(), be.player.getY(), be.player.getZ()), 0.0001f, new Color(be.color).getRed(), new Color(be.color).getGreen(), new Color(be.color).getBlue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.drmangotea.tfmg.content.electricity.connection.cables;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
|
||||
import com.simibubi.create.foundation.networking.BlockEntityDataPacket;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
||||
public class CablePacket extends BlockEntityDataPacket<SmartBlockEntity> {
|
||||
|
||||
|
||||
|
||||
|
||||
public CablePacket(BlockPos pos) {
|
||||
super(pos);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public CablePacket(FriendlyByteBuf buffer) {
|
||||
super(buffer);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void writeData(FriendlyByteBuf buffer) {}
|
||||
|
||||
@Override
|
||||
protected void handlePacket(SmartBlockEntity blockEntity) {
|
||||
|
||||
if(blockEntity instanceof CableConnectorBlockEntity be) {
|
||||
be.removeConnections(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.drmangotea.tfmg.content.electricity.connection.cables;
|
||||
|
||||
import com.simibubi.create.content.contraptions.behaviour.dispenser.SimplePos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Vec3i;
|
||||
|
||||
public class CablePos extends SimplePos {
|
||||
public CablePos(double x, double y, double z) {
|
||||
super(x, y, z);
|
||||
}
|
||||
public CablePos subtract(CablePos pos) {
|
||||
return this.offset(-pos.x(), -pos.y(), -pos.z());
|
||||
}
|
||||
|
||||
public CablePos offset(double x, double y, double z) {
|
||||
return x == 0 && y == 0 && z == 0 ? this : new CablePos(this.x() + x, this.y() + y, this.z() + z);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.drmangotea.tfmg.content.electricity.connection.cables;
|
||||
|
||||
|
||||
public interface IHaveCables {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.drmangotea.tfmg.content.electricity.connection.cables;
|
||||
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import org.apache.http.impl.conn.Wire;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WireNetwork{
|
||||
|
||||
public long id;
|
||||
|
||||
public List<IHaveCables> connectors = new ArrayList<>();
|
||||
|
||||
public int voltage;
|
||||
|
||||
public float resistance;
|
||||
|
||||
|
||||
public WireNetwork(long id){
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void add(IHaveCables be) {
|
||||
List<Long> posList = new ArrayList<>();
|
||||
|
||||
connectors.forEach(member -> posList.add(member.getId()));
|
||||
|
||||
if (posList.contains(be.getId()))
|
||||
return;
|
||||
connectors.add(be);
|
||||
|
||||
}
|
||||
|
||||
public void updateCables(){
|
||||
|
||||
|
||||
for(IHaveCables cable : connectors){
|
||||
if(cable instanceof IElectric be){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.drmangotea.tfmg.content.electricity.connection.diagonal;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.base.TFMGShapes;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.simibubi.create.content.equipment.wrench.IWrenchable;
|
||||
import com.simibubi.create.foundation.block.IBE;
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.DirectionalBlock;
|
||||
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Objects;
|
||||
|
||||
@SuppressWarnings({"unused","deprecation"})
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
public class DiagonalCableBlock extends DirectionalBlock implements SimpleWaterloggedBlock, IWrenchable, IBE<DiagonalCableBlockEntity> {
|
||||
|
||||
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
||||
public static final BooleanProperty FACING_UP = BooleanProperty.create("facing_up");
|
||||
public DiagonalCableBlock(Properties p_54120_) {
|
||||
super(p_54120_);
|
||||
this.registerDefaultState(this.stateDefinition.any().setValue(WATERLOGGED, Boolean.FALSE).setValue(FACING, Direction.NORTH).setValue(FACING_UP, false));
|
||||
}
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> p_55125_) {
|
||||
p_55125_.add(WATERLOGGED,FACING, FACING_UP);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FluidState getFluidState(BlockState p_51475_) {
|
||||
return p_51475_.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(p_51475_);
|
||||
}
|
||||
@Override
|
||||
public void onPlace(BlockState pState, Level level, BlockPos pos, BlockState pOldState, boolean pIsMoving) {
|
||||
withBlockEntityDo(level,pos, IElectric::onPlaced);
|
||||
}
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
}
|
||||
public VoxelShape getShape(BlockState state, BlockGetter p_54562_, BlockPos p_54563_, CollisionContext p_54564_) {
|
||||
|
||||
|
||||
|
||||
|
||||
if (state.getValue(FACING_UP)) {
|
||||
return TFMGShapes.DIAGONAL_CABLE_BLOCK_UP.get(state.getValue(FACING));
|
||||
}
|
||||
|
||||
|
||||
return TFMGShapes.DIAGONAL_CABLE_BLOCK_DOWN.get(state.getValue(FACING));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult onWrenched(BlockState state, UseOnContext context) {
|
||||
InteractionResult onWrenched = IWrenchable.super.onWrenched(state, context);
|
||||
if (!onWrenched.consumesAction())
|
||||
return onWrenched;
|
||||
|
||||
context.getLevel().setBlock(context.getClickedPos(),state.setValue(FACING_UP,!state.getValue(FACING_UP)),2);
|
||||
|
||||
withBlockEntityDo(context.getLevel(),context.getClickedPos(), IElectric::onPlaced);
|
||||
playRotateSound(context.getLevel(), context.getClickedPos());
|
||||
return onWrenched;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState updateShape(BlockState p_51461_, Direction p_51462_, BlockState p_51463_, LevelAccessor p_51464_, BlockPos p_51465_, BlockPos p_51466_) {
|
||||
if (p_51461_.getValue(WATERLOGGED)) {
|
||||
p_51464_.scheduleTick(p_51465_, Fluids.WATER, Fluids.WATER.getTickDelay(p_51464_));
|
||||
}
|
||||
|
||||
return super.updateShape(p_51461_, p_51462_, p_51463_, p_51464_, p_51465_, p_51466_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Nullable
|
||||
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
||||
FluidState fluidstate = context.getLevel().getFluidState(context.getClickedPos());
|
||||
boolean flag = fluidstate.getType() == Fluids.WATER;
|
||||
Direction facing = Objects.requireNonNull(context.getPlayer()).getDirection();
|
||||
Direction clickedFace = context.getClickedFace();
|
||||
|
||||
if (context.getPlayer() != null && context.getPlayer().isShiftKeyDown()) {
|
||||
if (clickedFace == Direction.DOWN)
|
||||
return defaultBlockState().setValue(FACING, facing.getOpposite()).setValue(FACING_UP,true).setValue(WATERLOGGED, flag);
|
||||
else
|
||||
return defaultBlockState().setValue(FACING, facing.getOpposite()).setValue(FACING_UP,false).setValue(WATERLOGGED, flag);
|
||||
}
|
||||
if (clickedFace == Direction.DOWN)
|
||||
return defaultBlockState().setValue(FACING, facing).setValue(FACING_UP,true).setValue(WATERLOGGED, flag);
|
||||
|
||||
|
||||
return defaultBlockState().setValue(FACING, facing).setValue(FACING_UP,false).setValue(WATERLOGGED, flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<DiagonalCableBlockEntity> getBlockEntityClass() {
|
||||
return DiagonalCableBlockEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntityType<? extends DiagonalCableBlockEntity> getBlockEntityType() {
|
||||
return TFMGBlockEntities.DIAGONAL_CABLE_BLOCK.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.drmangotea.tfmg.content.electricity.connection.diagonal;
|
||||
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.content.electricity.base.ElectricBlockEntity;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import static com.drmangotea.tfmg.content.electricity.connection.diagonal.DiagonalCableBlock.FACING_UP;
|
||||
import static net.minecraft.world.level.block.DirectionalBlock.FACING;
|
||||
|
||||
public class DiagonalCableBlockEntity extends ElectricBlockEntity {
|
||||
public DiagonalCableBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasElectricitySlot(Direction direction) {
|
||||
|
||||
if(getBlockState().getValue(FACING_UP)){
|
||||
|
||||
return direction == Direction.UP||direction == getBlockState().getValue(FACING);
|
||||
|
||||
|
||||
}else {
|
||||
return direction == Direction.DOWN||direction == getBlockState().getValue(FACING);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.drmangotea.tfmg.content.electricity.connection.diagonal;
|
||||
|
||||
import com.simibubi.create.foundation.data.SpecialBlockStateGen;
|
||||
import com.tterrag.registrate.providers.DataGenContext;
|
||||
import com.tterrag.registrate.providers.RegistrateBlockstateProvider;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.client.model.generators.ModelFile;
|
||||
|
||||
import static com.simibubi.create.foundation.data.AssetLookup.partialBaseModel;
|
||||
|
||||
public class DiagonalCableGenerator extends SpecialBlockStateGen {
|
||||
|
||||
@Override
|
||||
protected int getXRotation(BlockState state) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getYRotation(BlockState state) {
|
||||
return switch (state.getValue(DiagonalCableBlock.FACING)) {
|
||||
case NORTH -> 270;
|
||||
case SOUTH -> 90;
|
||||
case WEST -> 180;
|
||||
case EAST -> 0;
|
||||
case DOWN -> 0;
|
||||
case UP -> 0;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Block> ModelFile getModel(DataGenContext<Block, T> ctx, RegistrateBlockstateProvider prov,
|
||||
BlockState state) {
|
||||
// return AssetLookup.forPowered(ctx, prov)
|
||||
// .apply(state);
|
||||
|
||||
return state.getValue(DiagonalCableBlock.FACING_UP) ? partialBaseModel(ctx, prov, "up")
|
||||
: partialBaseModel(ctx, prov);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
package com.drmangotea.tfmg.content.electricity.connection.tube;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.base.TFMGShapes;
|
||||
import com.drmangotea.tfmg.content.decoration.concrete.ConcreteloggedBlock;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlocks;
|
||||
import com.drmangotea.tfmg.registry.TFMGPackets;
|
||||
import com.simibubi.create.foundation.block.IBE;
|
||||
import com.simibubi.create.foundation.block.ProperWaterloggedBlock;
|
||||
import com.simibubi.create.foundation.placement.IPlacementHelper;
|
||||
import com.simibubi.create.foundation.placement.PlacementHelpers;
|
||||
import com.simibubi.create.foundation.placement.PlacementOffset;
|
||||
import com.simibubi.create.foundation.placement.PoleHelper;
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.RotatedPillarBlock;
|
||||
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class CableTubeBlock extends RotatedPillarBlock implements IBE<CableTubeBlockEntity>, ConcreteloggedBlock {
|
||||
|
||||
public static final int placementHelperId = PlacementHelpers.register(new PlacementHelper());
|
||||
|
||||
public final boolean concreteEncased;
|
||||
|
||||
public CableTubeBlock(Properties p_49795_, boolean concreteEncased) {
|
||||
super(p_49795_);
|
||||
this.registerDefaultState(this.stateDefinition.any().setValue(CONCRETELOGGED, false).setValue(AXIS, Direction.Axis.Y));
|
||||
this.concreteEncased = concreteEncased;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidState getFluidState(BlockState p_60577_) {
|
||||
return fluidState(p_60577_);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||
builder.add(CONCRETELOGGED);
|
||||
super.createBlockStateDefinition(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource randomSource) {
|
||||
|
||||
if (state.is(TFMGBlocks.CABLE_TUBE.get()))
|
||||
tickDrying(level, state, TFMGBlocks.CONCRETE_ENCASED_CABLE_TUBE.getDefaultState().setValue(AXIS, state.getValue(AXIS)), pos, randomSource);
|
||||
|
||||
if (state.is(TFMGBlocks.ELECTRIC_POST.get()))
|
||||
tickDrying(level, state, TFMGBlocks.CONCRETE_ENCASED_CABLE_TUBE.getDefaultState().setValue(AXIS, state.getValue(AXIS)), pos, randomSource);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isRandomlyTicking(BlockState p_49921_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlace(BlockState pState, Level level, BlockPos pos, BlockState pOldState, boolean pIsMoving) {
|
||||
withBlockEntityDo(level, pos, IElectric::onPlaced);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState updateShape(BlockState pState, Direction pFacing, BlockState pFacingState, LevelAccessor pLevel,
|
||||
BlockPos pCurrentPos, BlockPos pFacingPos) {
|
||||
if(!concreteEncased)
|
||||
updateConcrete(pLevel, pState, pCurrentPos);
|
||||
return super.updateShape(pState, pFacing, pFacingState, pLevel, pCurrentPos, pFacingPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) {
|
||||
return concreteEncased ? super.getShape(pState, pLevel, pPos, pContext) : TFMGShapes.CABLE_TUBE.get(pState.getValue(AXIS));
|
||||
}
|
||||
|
||||
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
||||
BlockState state = this.defaultBlockState().setValue(AXIS, context.getClickedFace().getAxis());
|
||||
|
||||
return concreteEncased ? state : withConcrete(state, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<CableTubeBlockEntity> getBlockEntityClass() {
|
||||
return CableTubeBlockEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntityType<? extends CableTubeBlockEntity> getBlockEntityType() {
|
||||
return TFMGBlockEntities.CABLE_TUBE.get();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand,
|
||||
BlockHitResult pHit) {
|
||||
|
||||
|
||||
|
||||
|
||||
ItemStack itemInHand = player.getItemInHand(hand);
|
||||
|
||||
IPlacementHelper helper = PlacementHelpers.get(placementHelperId);
|
||||
if (helper.matchesItem(itemInHand)) {
|
||||
return helper.getOffset(player, level, state, pos, pHit)
|
||||
.placeInWorld(level, (BlockItem) itemInHand.getItem(), player, hand, pHit);
|
||||
}
|
||||
|
||||
|
||||
return concreteEncased ? InteractionResult.PASS : onClicked(level, pos, state, player, hand);
|
||||
}
|
||||
|
||||
@MethodsReturnNonnullByDefault
|
||||
private static class PlacementHelper extends PoleHelper<Direction.Axis> {
|
||||
|
||||
|
||||
private PlacementHelper() {
|
||||
super(state -> state.getBlock() instanceof CableTubeBlock, state -> state.getValue(AXIS), AXIS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate<ItemStack> getItemPredicate() {
|
||||
return i -> i.getItem() instanceof BlockItem
|
||||
&& ((BlockItem) i.getItem()).getBlock() instanceof CableTubeBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate<BlockState> getStatePredicate() {
|
||||
return s -> s.getBlock() instanceof CableTubeBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlacementOffset getOffset(Player player, Level world, BlockState state, BlockPos pos,
|
||||
BlockHitResult ray) {
|
||||
PlacementOffset offset = super.getOffset(player, world, state, pos, ray);
|
||||
if (offset.isSuccessful())
|
||||
offset.withTransform(offset.getTransform()
|
||||
.andThen(s -> state.setValue(AXIS, state.getValue(AXIS))));
|
||||
return offset;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.drmangotea.tfmg.content.electricity.connection.tube;
|
||||
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.content.electricity.base.ElectricBlockEntity;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import static net.minecraft.world.level.block.RotatedPillarBlock.AXIS;
|
||||
|
||||
public class CableTubeBlockEntity extends ElectricBlockEntity {
|
||||
public CableTubeBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasElectricitySlot(Direction direction) {
|
||||
return direction.getAxis() == getBlockState().getValue(AXIS);
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,17 @@ package com.drmangotea.tfmg.content.electricity.debug;
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.drmangotea.tfmg.base.TFMGUtils;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.content.electricity.connection.cables.CableConnectorBlockEntity;
|
||||
import com.drmangotea.tfmg.content.electricity.generators.GeneratorBlockEntity;
|
||||
import com.drmangotea.tfmg.content.electricity.utilities.diode.ElectricDiodeBlockEntity;
|
||||
import com.drmangotea.tfmg.content.engines.AbstractEngineBlockEntity;
|
||||
import com.drmangotea.tfmg.content.engines.base.AbstractEngineBlockEntity;
|
||||
import com.drmangotea.tfmg.content.engines.regular_engine.RegularEngineBlockEntity;
|
||||
import com.drmangotea.tfmg.content.machinery.metallurgy.blast_stove.BlastStoveBlockEntity;
|
||||
import com.drmangotea.tfmg.content.machinery.metallurgy.casting_basin.CastingBasinBlockEntity;
|
||||
import com.drmangotea.tfmg.content.machinery.metallurgy.coke_oven.CokeOvenBlockEntity;
|
||||
import com.drmangotea.tfmg.content.machinery.misc.vat_machines.base.VatBlockEntity;
|
||||
import com.drmangotea.tfmg.content.machinery.oil_processing.pumpjack.pumpjack.base.PumpjackBaseBlockEntity;
|
||||
import com.drmangotea.tfmg.content.machinery.oil_processing.surface_scanner.SurfaceScannerBlockEntity;
|
||||
import com.drmangotea.tfmg.registry.TFMGItems;
|
||||
import com.simibubi.create.content.fluids.tank.FluidTankBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
@@ -19,7 +21,10 @@ import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class DebugCinderBlockItem extends Item {
|
||||
public DebugCinderBlockItem(Properties p_41383_) {
|
||||
@@ -42,15 +47,20 @@ public class DebugCinderBlockItem extends Item {
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
if(level.getBlockEntity(pos) instanceof ElectricDiodeBlockEntity be){
|
||||
be.updateInFront();
|
||||
if(level.getBlockEntity(pos) instanceof CableConnectorBlockEntity be){
|
||||
//be.testSigma();
|
||||
be.wiresUpdated();
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
if(level.getBlockEntity(pos) instanceof IElectric be){
|
||||
if(context.getPlayer().isShiftKeyDown()) {
|
||||
// for (IElectric member : be.getOrCreateElectricNetwork().members) {
|
||||
// level.setBlock(BlockPos.of(member.getPos()).above(), Blocks.GOLD_BLOCK.defaultBlockState(), 3);
|
||||
// }
|
||||
TFMG.LOGGER.debug("///////////////////////////////");
|
||||
TFMG.LOGGER.debug("Group Resistance "+be.getData().group.resistance);
|
||||
TFMG.LOGGER.debug("Resistance "+be.resistance());
|
||||
TFMG.LOGGER.debug("Voltage Supply "+be.getData().voltageSupply);
|
||||
TFMG.LOGGER.debug("Higherst Current "+be.getData().highestCurrent);
|
||||
TFMG.LOGGER.debug("Group "+be.getData().group.id);
|
||||
TFMG.LOGGER.debug("///////////////////////////////");
|
||||
}else be.updateNextTick();
|
||||
}
|
||||
if(level.getBlockEntity(pos) instanceof CokeOvenBlockEntity be){
|
||||
@@ -65,6 +75,9 @@ public class DebugCinderBlockItem extends Item {
|
||||
}
|
||||
if(level.getBlockEntity(pos) instanceof FluidTankBlockEntity be){
|
||||
TFMGUtils.blowUpTank(be, 5);
|
||||
}
|
||||
if(level.getBlockEntity(pos) instanceof RegularEngineBlockEntity be){
|
||||
|
||||
}
|
||||
if(level.getBlockEntity(pos) instanceof AbstractEngineBlockEntity be){
|
||||
be.connect();
|
||||
@@ -76,15 +89,13 @@ public class DebugCinderBlockItem extends Item {
|
||||
be.findDeposits();
|
||||
}
|
||||
if(level.getBlockEntity(pos) instanceof PumpjackBaseBlockEntity be){
|
||||
be.loadDepositData();
|
||||
if(be.depositData !=null) {
|
||||
if(TFMG.DEPOSITS.depositData !=null) {
|
||||
if(context.getPlayer().isShiftKeyDown()){
|
||||
be.depositData.removeData();
|
||||
TFMG.DEPOSITS.depositData.removeData();
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
} else TFMG.DEPOSITS.depositData.removeEmptyDeposits();
|
||||
|
||||
|
||||
be.depositData.addDeposit(level, be.getBlockPos().below().asLong());
|
||||
}
|
||||
}
|
||||
return InteractionResult.SUCCESS;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.drmangotea.tfmg.content.electricity.electrians_wrench;
|
||||
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.drmangotea.tfmg.content.electricity.base.ConnectNeightborsPacket;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.registry.TFMGPackets;
|
||||
import com.simibubi.create.content.equipment.symmetryWand.SymmetryWandScreen;
|
||||
import com.simibubi.create.foundation.gui.ScreenOpener;
|
||||
import net.minecraft.core.BlockPos;
|
||||
@@ -15,6 +18,7 @@ import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
|
||||
public class ElectriciansWrenchItem extends Item {
|
||||
public ElectriciansWrenchItem(Properties p_41383_) {
|
||||
@@ -29,7 +33,7 @@ public class ElectriciansWrenchItem extends Item {
|
||||
if (player.isShiftKeyDown()) {
|
||||
if (level.isClientSide) {
|
||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
openWandGUI(itemStack);
|
||||
openWandGUI(itemStack, hand);
|
||||
});
|
||||
player.getCooldowns()
|
||||
.addCooldown(this, 5);
|
||||
@@ -46,8 +50,12 @@ public class ElectriciansWrenchItem extends Item {
|
||||
|
||||
if(!context.getPlayer().isShiftKeyDown())
|
||||
if(level.getBlockEntity(pos) instanceof IElectric be){
|
||||
|
||||
be.getData().group.id = context.getItemInHand().getOrCreateTag().getInt("Number");
|
||||
|
||||
|
||||
be.updateNextTick();
|
||||
be.sendStuff();
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +63,7 @@ public class ElectriciansWrenchItem extends Item {
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private void openWandGUI(ItemStack itemStack) {
|
||||
ScreenOpener.open(new ElectriciansWrenchScreen(itemStack));
|
||||
private void openWandGUI(ItemStack itemStack, InteractionHand hand) {
|
||||
ScreenOpener.open(new ElectriciansWrenchScreen(itemStack, hand));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.drmangotea.tfmg.content.electricity.electrians_wrench;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.simibubi.create.content.equipment.zapper.ZapperItem;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
public class ElectriciansWrenchPacket extends SimplePacketBase {
|
||||
|
||||
|
||||
int group;
|
||||
protected InteractionHand hand;
|
||||
|
||||
public ElectriciansWrenchPacket(int group, InteractionHand hand) {
|
||||
this.group = group;
|
||||
this.hand = hand;
|
||||
}
|
||||
|
||||
public ElectriciansWrenchPacket(FriendlyByteBuf buffer) {
|
||||
this.group = buffer.readInt();
|
||||
hand = buffer.readEnum(InteractionHand.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buffer) {
|
||||
buffer.writeInt(group);
|
||||
buffer.writeEnum(hand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(NetworkEvent.Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
if (stack.getItem() instanceof ElectriciansWrenchItem) {
|
||||
applyGroup(stack);
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void applyGroup(ItemStack stack){
|
||||
|
||||
TFMG.LOGGER.debug("Packet Mogus "+group);
|
||||
|
||||
stack.getOrCreateTag().putInt("Number", group);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +1,30 @@
|
||||
package com.drmangotea.tfmg.content.electricity.electrians_wrench;
|
||||
|
||||
import com.drmangotea.tfmg.registry.TFMGGuiTextures;
|
||||
import com.drmangotea.tfmg.registry.TFMGPackets;
|
||||
import com.simibubi.create.foundation.gui.AbstractSimiScreen;
|
||||
import com.simibubi.create.foundation.gui.AllIcons;
|
||||
import com.simibubi.create.foundation.gui.element.GuiGameElement;
|
||||
import com.simibubi.create.foundation.gui.widget.IconButton;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class ElectriciansWrenchScreen extends AbstractSimiScreen {
|
||||
|
||||
ItemStack wrench;
|
||||
protected InteractionHand hand;
|
||||
private IconButton addButton;
|
||||
private IconButton subtractButton;
|
||||
private IconButton confirmButton;
|
||||
|
||||
public ElectriciansWrenchScreen(ItemStack wrench) {
|
||||
int group;
|
||||
|
||||
public ElectriciansWrenchScreen(ItemStack wrench, InteractionHand hand) {
|
||||
this.wrench = wrench;
|
||||
this.hand = hand;
|
||||
this.group = wrench.getOrCreateTag().getInt("Number");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -25,7 +32,8 @@ public class ElectriciansWrenchScreen extends AbstractSimiScreen {
|
||||
int x = guiLeft;
|
||||
int y = guiTop;
|
||||
|
||||
int value = wrench.getOrCreateTag().getInt("Number");
|
||||
//int value = wrench.getOrCreateTag().getInt("Number");
|
||||
int value = group;
|
||||
String valueString = String.valueOf(value);
|
||||
background().render(graphics, x, y);
|
||||
graphics.drawString(font, valueString, x + 90 -(3*valueString.length()), y + 39, 0xffffff, false);
|
||||
@@ -57,19 +65,46 @@ public class ElectriciansWrenchScreen extends AbstractSimiScreen {
|
||||
addRenderableWidget(addButton);
|
||||
addRenderableWidget(subtractButton);
|
||||
}
|
||||
|
||||
public void addNumber(){
|
||||
group++;
|
||||
// CompoundTag tag = wrench.getOrCreateTag();
|
||||
//
|
||||
// int number = tag.getInt("Number");
|
||||
// tag.putInt("Number", number+1);
|
||||
//
|
||||
// ElectritiansWrenchPacket packet = new ElectritiansWrenchPacket(tag.getInt("Number"), hand);
|
||||
// packet.applyGroup(wrench);
|
||||
// TFMGPackets.getChannel().sendToServer(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
super.onClose();
|
||||
|
||||
|
||||
CompoundTag tag = wrench.getOrCreateTag();
|
||||
|
||||
int number = tag.getInt("Number");
|
||||
tag.putInt("Number", number+1);
|
||||
tag.putInt("Number", group);
|
||||
|
||||
ElectriciansWrenchPacket packet = new ElectriciansWrenchPacket(group, hand);
|
||||
packet.applyGroup(wrench);
|
||||
TFMGPackets.getChannel().sendToServer(packet);
|
||||
}
|
||||
|
||||
public void substractNumber(){
|
||||
CompoundTag tag = wrench.getOrCreateTag();
|
||||
if(group>0)
|
||||
group--;
|
||||
|
||||
int number = tag.getInt("Number");
|
||||
if(number>0)
|
||||
tag.putInt("Number", number-1);
|
||||
//CompoundTag tag = wrench.getOrCreateTag();
|
||||
//
|
||||
//int number = tag.getInt("Number");
|
||||
//if(number>0)
|
||||
// tag.putInt("Number", number-1);
|
||||
//
|
||||
//ElectritiansWrenchPacket packet = new ElectritiansWrenchPacket(tag.getInt("Number"), hand);
|
||||
//packet.applyGroup(wrench);
|
||||
//TFMGPackets.getChannel().sendToServer(packet);
|
||||
}
|
||||
|
||||
public TFMGGuiTextures background(){
|
||||
|
||||
@@ -39,7 +39,7 @@ public class GeneratorBlockEntity extends KineticElectricBlockEntity {
|
||||
if(getNetworkResistance() ==0)
|
||||
return super.calculateStressApplied();
|
||||
|
||||
return (super.calculateStressApplied()*getGeneratorLoad()*0.0005f);
|
||||
return (super.calculateStressApplied()*getGeneratorLoad()*0.0001f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.drmangotea.tfmg.content.electricity.generators.large_generator;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.base.TFMGShapes;
|
||||
import com.drmangotea.tfmg.content.electricity.base.ConnectNeightborsPacket;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.drmangotea.tfmg.registry.TFMGPackets;
|
||||
import com.simibubi.create.content.kinetics.base.RotatedPillarKineticBlock;
|
||||
import com.simibubi.create.foundation.block.IBE;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
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;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
|
||||
public class RotorBlock extends RotatedPillarKineticBlock implements IBE<RotorBlockEntity> {
|
||||
public RotorBlock(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction.Axis getRotationAxis(BlockState state) {
|
||||
return state.getValue(AXIS);
|
||||
}
|
||||
@Override
|
||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
||||
return face.getAxis() == getRotationAxis(state);
|
||||
}
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState pState, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
|
||||
return TFMGShapes.ROTOR.get(Direction.get(Direction.AxisDirection.POSITIVE,pState.getValue(AXIS)));
|
||||
}
|
||||
@Override
|
||||
public void onPlace(BlockState pState, Level level, BlockPos pos, BlockState pOldState, boolean pIsMoving) {
|
||||
withBlockEntityDo(level, pos, IElectric::onPlaced);
|
||||
}
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RenderShape getRenderShape(BlockState pState) {
|
||||
return RenderShape.ENTITYBLOCK_ANIMATED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<RotorBlockEntity> getBlockEntityClass() {
|
||||
return RotorBlockEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntityType<? extends RotorBlockEntity> getBlockEntityType() {
|
||||
return TFMGBlockEntities.ROTOR.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
package com.drmangotea.tfmg.content.electricity.generators.large_generator;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.config.TFMGConfigs;
|
||||
import com.drmangotea.tfmg.content.electricity.base.KineticElectricBlockEntity;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlocks;
|
||||
import com.simibubi.create.foundation.utility.animation.LerpedFloat;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import com.drmangotea.tfmg.content.electricity.generators.large_generator.StatorBlock.StatorState;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.drmangotea.tfmg.content.electricity.generators.large_generator.StatorBlock.STATOR_STATE;
|
||||
import static com.drmangotea.tfmg.content.electricity.generators.large_generator.StatorBlock.VALUE;
|
||||
import static com.simibubi.create.content.kinetics.base.RotatedPillarKineticBlock.AXIS;
|
||||
import static net.minecraft.core.Direction.*;
|
||||
import static net.minecraft.world.level.block.DirectionalBlock.FACING;
|
||||
|
||||
|
||||
public class RotorBlockEntity extends KineticElectricBlockEntity {
|
||||
|
||||
|
||||
|
||||
|
||||
LerpedFloat visualSpeed = LerpedFloat.linear();
|
||||
float angle;
|
||||
|
||||
|
||||
List<BlockPos> stators = new ArrayList<>();
|
||||
|
||||
public static final Map<Axis,Map<StatorOffset, BlockState>> statorPosition = setStatorPositons();
|
||||
|
||||
public RotorBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AABB createRenderBoundingBox() {
|
||||
return super.createRenderBoundingBox().inflate(2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void read(CompoundTag compound, boolean clientPacket) {
|
||||
super.read(compound, clientPacket);
|
||||
visualSpeed.chase(getGeneratedSpeed(), 1 / 128f, LerpedFloat.Chaser.EXP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
manageRotation();
|
||||
}
|
||||
@Override
|
||||
public void lazyTick() {
|
||||
super.lazyTick();
|
||||
|
||||
findStators();
|
||||
}
|
||||
@Override
|
||||
public void onPlaced() {
|
||||
super.onPlaced();
|
||||
findStators();
|
||||
}
|
||||
@Override
|
||||
public int voltageGeneration() {
|
||||
return (int) Math.min(255,generation());
|
||||
}
|
||||
|
||||
public int generation() {
|
||||
float modifier = TFMGConfigs.common().machines.largeGeneratorFeModifier.getF();
|
||||
return (int) (((Math.log(Math.abs(getSpeed()))/Math.log(1.026))-22)*modifier*3.5f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int powerGeneration() {
|
||||
return generation()*40;
|
||||
}
|
||||
public void findStators(){
|
||||
Axis axis = getBlockState().getValue(AXIS);
|
||||
|
||||
Map<StatorOffset, BlockState> position = statorPosition.get(axis);
|
||||
stators = new ArrayList<>();
|
||||
position.forEach(((offset, state) -> {
|
||||
BlockPos pos = getBlockPos().relative(offset.direction1);
|
||||
if (offset.direction2.isPresent())
|
||||
pos = pos.relative(offset.direction2.get());
|
||||
|
||||
if (level.getBlockEntity(pos) instanceof StatorBlockEntity be) {
|
||||
|
||||
if (be.rotor == null || be.rotor == getBlockPos()) {
|
||||
|
||||
stators.add(pos);
|
||||
level.setBlock(pos, state, 2);
|
||||
be.rotor = getBlockPos();
|
||||
|
||||
} else {
|
||||
stators = new ArrayList<>();
|
||||
updateNextTick();
|
||||
}
|
||||
} else {
|
||||
stators = new ArrayList<>();
|
||||
updateNextTick();
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
public void manageRotation(){
|
||||
float targetSpeed = getSpeed();
|
||||
visualSpeed.updateChaseTarget(targetSpeed);
|
||||
visualSpeed.tickChaser();
|
||||
angle += visualSpeed.getValue() * 3 / 10f;
|
||||
angle %= 360;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasElectricitySlot(Direction direction) {
|
||||
return direction.getAxis()!=getBlockState().getValue(AXIS);
|
||||
}
|
||||
|
||||
public static Map<Axis,Map<StatorOffset, BlockState>> setStatorPositons(){
|
||||
Map<Axis,Map<StatorOffset, BlockState>> statorPositions = new HashMap<>();
|
||||
BlockState defaultState = TFMGBlocks.STATOR.getDefaultState();
|
||||
BlockState cornerState = defaultState.setValue(STATOR_STATE,StatorState.CORNER);
|
||||
BlockState horizontal = defaultState.setValue(STATOR_STATE,StatorState.CORNER_HORIZONTAL);
|
||||
BlockState sideState = defaultState.setValue(STATOR_STATE,StatorState.SIDE);
|
||||
BlockState cornerFlipped = cornerState.setValue(VALUE, false);
|
||||
BlockState sideFlipped = sideState.setValue(VALUE, false);
|
||||
Map<StatorOffset, BlockState> xPos = new HashMap<>();
|
||||
xPos.put(pos(UP ), sideFlipped .setValue(FACING,DOWN ));
|
||||
xPos.put(pos(DOWN ), sideFlipped .setValue(FACING,UP ));
|
||||
xPos.put(pos(NORTH ), sideFlipped .setValue(FACING,SOUTH ));
|
||||
xPos.put(pos(SOUTH ), sideFlipped .setValue(FACING,NORTH ));
|
||||
xPos.put(pos(UP,NORTH ), cornerState .setValue(FACING,EAST ));
|
||||
xPos.put(pos(UP,SOUTH ), cornerState .setValue(FACING,WEST ));
|
||||
xPos.put(pos(DOWN,NORTH ), cornerFlipped.setValue(FACING,EAST ));
|
||||
xPos.put(pos(DOWN,SOUTH ), cornerFlipped.setValue(FACING,WEST ));
|
||||
Map<StatorOffset, BlockState> yPos = new HashMap<>();
|
||||
yPos.put(pos(EAST ), sideState .setValue(FACING,WEST ));
|
||||
yPos.put(pos(WEST ), sideState .setValue(FACING,EAST ));
|
||||
yPos.put(pos(SOUTH ), sideState .setValue(FACING,NORTH ));
|
||||
yPos.put(pos(NORTH ), sideState .setValue(FACING,SOUTH ));
|
||||
yPos.put(pos(NORTH,WEST ), horizontal .setValue(FACING,NORTH));
|
||||
yPos.put(pos(SOUTH,EAST ), horizontal .setValue(FACING,SOUTH));
|
||||
yPos.put(pos(SOUTH,WEST ), horizontal .setValue(FACING,WEST ));
|
||||
yPos.put(pos(NORTH,EAST ), horizontal .setValue(FACING,EAST ));
|
||||
Map<StatorOffset, BlockState> zPos = new HashMap<>();
|
||||
zPos.put(pos(UP ), sideState .setValue(FACING,DOWN ));
|
||||
zPos.put(pos(DOWN ), sideState .setValue(FACING,UP ));
|
||||
zPos.put(pos(WEST ), sideFlipped .setValue(FACING,EAST ));
|
||||
zPos.put(pos(EAST ), sideFlipped .setValue(FACING,WEST ));
|
||||
zPos.put(pos(UP,WEST ), cornerState .setValue(FACING,UP ));
|
||||
zPos.put(pos(UP,EAST ), cornerState .setValue(FACING,SOUTH ));
|
||||
zPos.put(pos(DOWN,WEST ), cornerFlipped.setValue(FACING,UP ));
|
||||
zPos.put(pos(DOWN,EAST ), cornerFlipped.setValue(FACING,SOUTH ));
|
||||
statorPositions.put(Axis.X,xPos);
|
||||
statorPositions.put(Axis.Y,yPos);
|
||||
statorPositions.put(Axis.Z,zPos);
|
||||
return statorPositions;
|
||||
}
|
||||
|
||||
private static StatorOffset pos(Direction dir1){
|
||||
return new StatorOffset(dir1, Optional.empty());
|
||||
}
|
||||
|
||||
private static StatorOffset pos(Direction dir1,Direction dir2){
|
||||
return new StatorOffset(dir1, Optional.of(dir2));
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class StatorOffset{
|
||||
public final Direction direction1;
|
||||
public final Optional<Direction> direction2;
|
||||
|
||||
public StatorOffset(Direction dir1,Optional<Direction> dir2){
|
||||
this.direction1 = dir1;
|
||||
this.direction2 = dir2;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.drmangotea.tfmg.content.electricity.generators.large_generator;
|
||||
|
||||
|
||||
import com.jozufozu.flywheel.api.MaterialManager;
|
||||
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
||||
import com.jozufozu.flywheel.core.materials.model.ModelData;
|
||||
import com.jozufozu.flywheel.util.transform.TransformStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.simibubi.create.content.kinetics.base.KineticBlockEntityInstance;
|
||||
import com.simibubi.create.content.kinetics.base.flwdata.RotatingData;
|
||||
import com.simibubi.create.foundation.utility.AngleHelper;
|
||||
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
||||
import net.minecraft.core.Direction;
|
||||
|
||||
import static com.simibubi.create.content.kinetics.base.RotatedPillarKineticBlock.AXIS;
|
||||
|
||||
public class RotorInstance extends KineticBlockEntityInstance<RotorBlockEntity> implements DynamicInstance {
|
||||
|
||||
protected final RotatingData shaft;
|
||||
protected final ModelData wheel;
|
||||
|
||||
|
||||
protected float lastAngle = Float.NaN;
|
||||
|
||||
public RotorInstance(MaterialManager materialManager, RotorBlockEntity blockEntity) {
|
||||
super(materialManager, blockEntity);
|
||||
|
||||
shaft = setup(getRotatingMaterial().getModel(shaft())
|
||||
.createInstance());
|
||||
wheel = getTransformMaterial().getModel(blockState)
|
||||
.createInstance();
|
||||
|
||||
animate(blockEntity.angle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beginFrame() {
|
||||
|
||||
float partialTicks = AnimationTickHolder.getPartialTicks();
|
||||
|
||||
float speed = blockEntity.visualSpeed.getValue(partialTicks) * 3 / 10f;
|
||||
float angle = blockEntity.angle + speed * partialTicks;
|
||||
|
||||
if (Math.abs(angle - lastAngle) < 0.001)
|
||||
return;
|
||||
|
||||
animate(angle);
|
||||
|
||||
lastAngle = angle;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void animate(float angle) {
|
||||
PoseStack ms = new PoseStack();
|
||||
TransformStack msr = TransformStack.cast(ms);
|
||||
|
||||
msr.translate(getInstancePosition());
|
||||
msr.centre()
|
||||
.rotate(Direction.get(Direction.AxisDirection.POSITIVE, axis), AngleHelper.rad(angle))
|
||||
.unCentre();
|
||||
|
||||
wheel.setTransform(ms);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
updateRotation(shaft);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLight() {
|
||||
relight(pos, shaft, wheel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
shaft.delete();
|
||||
wheel.delete();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.drmangotea.tfmg.content.electricity.generators.large_generator;
|
||||
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.simibubi.create.content.kinetics.base.KineticBlockEntityRenderer;
|
||||
import com.simibubi.create.foundation.render.CachedBufferer;
|
||||
import com.simibubi.create.foundation.render.SuperByteBuffer;
|
||||
import com.simibubi.create.foundation.utility.AngleHelper;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import static com.simibubi.create.content.kinetics.base.RotatedPillarKineticBlock.AXIS;
|
||||
|
||||
public class RotorRenderer extends KineticBlockEntityRenderer<RotorBlockEntity> {
|
||||
|
||||
public RotorRenderer(BlockEntityRendererProvider.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderSafe(RotorBlockEntity be, float partialTicks, PoseStack ms, MultiBufferSource buffer,
|
||||
int light, int overlay) {
|
||||
super.renderSafe(be, partialTicks, ms, buffer, light, overlay);
|
||||
|
||||
if (Backend.canUseInstancing(be.getLevel()))
|
||||
return;
|
||||
|
||||
BlockState blockState = be.getBlockState();
|
||||
|
||||
float speed = be.visualSpeed.getValue(partialTicks) * 3 / 10f;
|
||||
float angle = be.angle + speed * partialTicks;
|
||||
|
||||
VertexConsumer vb = buffer.getBuffer(RenderType.cutoutMipped());
|
||||
|
||||
ms.pushPose();
|
||||
|
||||
renderRotor(be, ms, light, blockState, angle, vb);
|
||||
|
||||
ms.popPose();
|
||||
}
|
||||
|
||||
private void renderRotor(RotorBlockEntity be, PoseStack ms, int light, BlockState blockState, float angle,
|
||||
VertexConsumer vb) {
|
||||
SuperByteBuffer wheel = CachedBufferer.block(blockState);
|
||||
kineticRotationTransform(wheel, be, getRotationAxisOf(be), AngleHelper.rad(angle), light);
|
||||
wheel.renderInto(ms, vb);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState getRenderedBlockState(RotorBlockEntity be) {
|
||||
return shaft(getRotationAxisOf(be));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.drmangotea.tfmg.content.electricity.generators.large_generator;
|
||||
|
||||
import com.drmangotea.tfmg.base.TFMGShapes;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.drmangotea.tfmg.registry.TFMGPackets;
|
||||
import com.simibubi.create.foundation.block.IBE;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.util.StringRepresentable;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.DirectionalBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
|
||||
public class StatorBlock extends DirectionalBlock implements IBE<StatorBlockEntity> {
|
||||
|
||||
|
||||
public static final BooleanProperty VALUE = BooleanProperty.create("value");
|
||||
public static final EnumProperty<StatorState> STATOR_STATE = EnumProperty.create("stator_state", StatorState.class);
|
||||
|
||||
public StatorBlock(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPlace(BlockState pState, Level level, BlockPos pos, BlockState pOldState, boolean pIsMoving) {
|
||||
withBlockEntityDo(level, pos, IElectric::onPlaced);
|
||||
}
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
|
||||
pBuilder.add(STATOR_STATE,FACING,VALUE);
|
||||
super.createBlockStateDefinition(pBuilder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, BlockGetter blockGetter, BlockPos pos, CollisionContext context) {
|
||||
|
||||
StatorState statorState = state.getValue(STATOR_STATE);
|
||||
boolean rotated = state.getValue(VALUE);
|
||||
Direction direction = state.getValue(FACING);
|
||||
|
||||
if(statorState == StatorState.CORNER){
|
||||
return rotated ? TFMGShapes.STATOR_ROTATED.get(direction) : TFMGShapes.STATOR.get(direction);
|
||||
}
|
||||
if(statorState == StatorState.CORNER_HORIZONTAL){
|
||||
|
||||
|
||||
return TFMGShapes.STATOR_VERTICAL.get(direction);
|
||||
}
|
||||
|
||||
|
||||
return super.getShape(state, blockGetter, pos, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<StatorBlockEntity> getBlockEntityClass() {
|
||||
return StatorBlockEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntityType<? extends StatorBlockEntity> getBlockEntityType() {
|
||||
return TFMGBlockEntities.STATOR.get();
|
||||
}
|
||||
|
||||
public enum StatorState implements StringRepresentable{
|
||||
|
||||
|
||||
SIDE("side"),
|
||||
CORNER_HORIZONTAL("corner_horizontal"),
|
||||
CORNER("corner")
|
||||
|
||||
|
||||
;
|
||||
final String name;
|
||||
StatorState(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getSerializedName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.drmangotea.tfmg.content.electricity.generators.large_generator;
|
||||
|
||||
import com.drmangotea.tfmg.content.electricity.base.ElectricBlockEntity;
|
||||
import com.simibubi.create.content.equipment.goggles.IHaveGoggleInformation;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
|
||||
public class StatorBlockEntity extends ElectricBlockEntity implements IHaveGoggleInformation {
|
||||
|
||||
public BlockPos rotor=null;
|
||||
public StatorBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
}
|
||||
public void setRotor(RotorBlockEntity be){
|
||||
rotor = be.getBlockPos();
|
||||
}
|
||||
@Override
|
||||
public void lazyTick() {
|
||||
super.lazyTick();
|
||||
if(rotor!=null)
|
||||
if(!(level.getBlockEntity(rotor) instanceof RotorBlockEntity))
|
||||
rotor = null;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.drmangotea.tfmg.content.electricity.generators.large_generator;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.simibubi.create.foundation.data.SpecialBlockStateGen;
|
||||
import com.tterrag.registrate.providers.DataGenContext;
|
||||
import com.tterrag.registrate.providers.RegistrateBlockstateProvider;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.client.model.generators.ModelFile;
|
||||
|
||||
|
||||
public class StatorGenerator extends SpecialBlockStateGen {
|
||||
|
||||
|
||||
protected int getXRotation(BlockState state) {
|
||||
|
||||
short value;
|
||||
switch ((Direction)state.getValue(StatorBlock.FACING)) {
|
||||
case NORTH, SOUTH, WEST, EAST:
|
||||
value = 0;
|
||||
break;
|
||||
|
||||
|
||||
|
||||
case DOWN:
|
||||
if(state.getValue(StatorBlock.STATOR_STATE)== StatorBlock.StatorState.CORNER) {
|
||||
value = 0;
|
||||
}else
|
||||
value = 90;
|
||||
break;
|
||||
case UP:
|
||||
if(state.getValue(StatorBlock.STATOR_STATE)== StatorBlock.StatorState.CORNER) {
|
||||
value = 0;
|
||||
}else
|
||||
value = 270;
|
||||
break;
|
||||
default:
|
||||
throw new IncompatibleClassChangeError();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
protected int getYRotation(BlockState state) {
|
||||
|
||||
short value;
|
||||
switch ((Direction)state.getValue(StatorBlock.FACING)) {
|
||||
case NORTH, DOWN, UP:
|
||||
value = 0;
|
||||
break;
|
||||
case SOUTH:
|
||||
value = 180;
|
||||
break;
|
||||
case WEST:
|
||||
value = 270;
|
||||
break;
|
||||
case EAST:
|
||||
value = 90;
|
||||
break;
|
||||
default:
|
||||
throw new IncompatibleClassChangeError();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public <T extends Block> ModelFile getModel(DataGenContext<Block, T> ctx, RegistrateBlockstateProvider prov,
|
||||
BlockState state) {
|
||||
|
||||
String path = "block/stator/block_"
|
||||
+ state.getValue(StatorBlock.STATOR_STATE).getSerializedName()
|
||||
;
|
||||
|
||||
if(state.getValue(StatorBlock.VALUE)&&state.getValue(StatorBlock.STATOR_STATE)== StatorBlock.StatorState.CORNER)
|
||||
path = path + "_up";
|
||||
if(state.getValue(StatorBlock.VALUE)&&state.getValue(StatorBlock.STATOR_STATE)== StatorBlock.StatorState.SIDE)
|
||||
path = path + "_rotated";
|
||||
|
||||
return prov.models()
|
||||
.getExistingFile(TFMG.asResource(path));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,13 @@ import com.simibubi.create.foundation.utility.VoxelShaper;
|
||||
import com.tterrag.registrate.util.entry.BlockEntityEntry;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
@@ -26,6 +33,7 @@ import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
@@ -60,8 +68,26 @@ public class LightBulbBlock extends WallMountBlock implements IBE<LightBulbBlock
|
||||
|
||||
return shape.get(pState.getValue(FACING));
|
||||
}
|
||||
@Override
|
||||
public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player player, InteractionHand pHand,
|
||||
BlockHitResult pHit) {
|
||||
if (player.isShiftKeyDown())
|
||||
return InteractionResult.PASS;
|
||||
ItemStack heldItem = player.getItemInHand(pHand);
|
||||
LightBulbBlockEntity be = getBlockEntity(pLevel, pPos);
|
||||
DyeColor dye = DyeColor.getColor(heldItem);
|
||||
if (be != null) {
|
||||
if (dye != null) {
|
||||
pLevel.playSound(null, pPos, SoundEvents.DYE_USE, SoundSource.BLOCKS, 1.0F, 1.0F);
|
||||
be.setColor(dye);
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> p_153687_) {
|
||||
p_153687_.add(LIGHT, WATERLOGGED,FACING);
|
||||
}
|
||||
|
||||
@@ -2,17 +2,21 @@ package com.drmangotea.tfmg.content.electricity.lights;
|
||||
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.drmangotea.tfmg.content.electricity.base.ElectricBlockEntity;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlocks;
|
||||
import com.drmangotea.tfmg.registry.TFMGPackets;
|
||||
import com.drmangotea.tfmg.registry.TFMGPartialModels;
|
||||
import com.jozufozu.flywheel.core.PartialModel;
|
||||
import com.simibubi.create.foundation.utility.NBTHelper;
|
||||
import com.simibubi.create.foundation.utility.animation.LerpedFloat;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
@@ -28,6 +32,9 @@ public class LightBulbBlockEntity extends ElectricBlockEntity {
|
||||
|
||||
boolean hasSignal;
|
||||
|
||||
public DyeColor color= DyeColor.WHITE;
|
||||
|
||||
|
||||
|
||||
public LightBulbBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
@@ -54,7 +61,18 @@ public class LightBulbBlockEntity extends ElectricBlockEntity {
|
||||
analogSignalChanged(level.getBestNeighborSignal(worldPosition));
|
||||
}
|
||||
}
|
||||
public void setColor(DyeColor color) {
|
||||
if(color==DyeColor.BLACK||color == DyeColor.LIGHT_GRAY|| color == DyeColor.GRAY)
|
||||
return;
|
||||
|
||||
this.color = color;
|
||||
notifyUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVoltage(int newVoltage) {
|
||||
super.setVoltage(newVoltage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float resistance() {
|
||||
@@ -75,6 +93,18 @@ public class LightBulbBlockEntity extends ElectricBlockEntity {
|
||||
neighbourChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void write(CompoundTag compound, boolean clientPacket) {
|
||||
super.write(compound, clientPacket);
|
||||
NBTHelper.writeEnum(compound,"color",color);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void read(CompoundTag compound, boolean clientPacket) {
|
||||
super.read(compound, clientPacket);
|
||||
color = NBTHelper.readEnum(compound,"color",DyeColor.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeInGroups() {
|
||||
return true;
|
||||
|
||||
@@ -10,8 +10,10 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.simibubi.create.foundation.blockEntity.renderer.SafeBlockEntityRenderer;
|
||||
import com.simibubi.create.foundation.render.CachedBufferer;
|
||||
import com.simibubi.create.foundation.render.RenderTypes;
|
||||
import com.simibubi.create.foundation.render.SuperByteBuffer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class LightBulbRenderer extends SafeBlockEntityRenderer<LightBulbBlockEntity> {
|
||||
@@ -32,11 +34,15 @@ public class LightBulbRenderer extends SafeBlockEntityRenderer<LightBulbBlockEnt
|
||||
int color = Math.min(100,(int) (glow/0.2f));
|
||||
if(be.glow.getValue()!=0) {
|
||||
|
||||
CachedBufferer.partialFacing(getLightModel(), blockState, blockState.getValue(WallMountBlock.FACING))
|
||||
SuperByteBuffer lightModel = CachedBufferer.partialFacing(getLightModel(), blockState, blockState.getValue(WallMountBlock.FACING))
|
||||
.light((int) glow * 3 + 40)
|
||||
.color(color, color, (int) (color * 0.8), 255)
|
||||
.disableDiffuse()
|
||||
.renderInto(ms, buffer.getBuffer(RenderTypes.getAdditive()));
|
||||
.disableDiffuse();
|
||||
if(be.color == DyeColor.WHITE){
|
||||
lightModel.color(color, color, (int) (color * 0.8), 255);
|
||||
}else lightModel.color(be.color.getTextColor());
|
||||
|
||||
lightModel.renderInto(ms, buffer.getBuffer(RenderTypes.getAdditive()));
|
||||
}
|
||||
ms.popPose();
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.drmangotea.tfmg.content.electricity.lights;
|
||||
package com.drmangotea.tfmg.content.electricity.lights.variants;
|
||||
|
||||
import com.drmangotea.tfmg.content.electricity.lights.LightBulbRenderer;
|
||||
import com.drmangotea.tfmg.registry.TFMGPartialModels;
|
||||
import com.jozufozu.flywheel.core.PartialModel;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
|
||||
public class AluminumLampRenderer extends LightBulbRenderer{
|
||||
public class AluminumLampRenderer extends LightBulbRenderer {
|
||||
public AluminumLampRenderer(BlockEntityRendererProvider.Context context) {
|
||||
super(context);
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.drmangotea.tfmg.content.electricity.lights;
|
||||
package com.drmangotea.tfmg.content.electricity.lights.variants;
|
||||
|
||||
import com.drmangotea.tfmg.content.electricity.lights.LightBulbRenderer;
|
||||
import com.drmangotea.tfmg.registry.TFMGPartialModels;
|
||||
import com.jozufozu.flywheel.core.PartialModel;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
|
||||
public class CircularLightRenderer extends LightBulbRenderer{
|
||||
public class CircularLightRenderer extends LightBulbRenderer {
|
||||
public CircularLightRenderer(BlockEntityRendererProvider.Context context) {
|
||||
super(context);
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.drmangotea.tfmg.content.electricity.lights;
|
||||
package com.drmangotea.tfmg.content.electricity.lights.variants;
|
||||
|
||||
import com.drmangotea.tfmg.content.electricity.lights.LightBulbRenderer;
|
||||
import com.drmangotea.tfmg.registry.TFMGPartialModels;
|
||||
import com.jozufozu.flywheel.core.PartialModel;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
|
||||
public class ModernLightRenderer extends LightBulbRenderer{
|
||||
public class ModernLightRenderer extends LightBulbRenderer {
|
||||
public ModernLightRenderer(BlockEntityRendererProvider.Context context) {
|
||||
super(context);
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public class AmmeterBlockEntity extends VoltMeterBlockEntity {
|
||||
|
||||
@Override
|
||||
public int getUnit(IElectric be) {
|
||||
return be.getMaxAmps();
|
||||
return (int) be.getData().highestCurrent;
|
||||
}
|
||||
@Override
|
||||
@SuppressWarnings("removal")
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.drmangotea.tfmg.content.electricity.measurement;
|
||||
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.drmangotea.tfmg.content.electricity.base.ElectricalNetwork;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.simibubi.create.content.equipment.goggles.IHaveGoggleInformation;
|
||||
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
|
||||
@@ -43,11 +45,14 @@ public class VoltMeterBlockEntity extends SmartBlockEntity implements IHaveGoggl
|
||||
@Override
|
||||
public void lazyTick() {
|
||||
super.lazyTick();
|
||||
if(!level.isClientSide)
|
||||
return;
|
||||
//if(!level.isClientSide)
|
||||
// return;
|
||||
BlockEntity beBehind = level.getBlockEntity(getBlockPos().relative(getBlockState().getValue(FACING).getOpposite()));
|
||||
|
||||
if(beBehind instanceof IElectric be){
|
||||
// TFMG.LOGGER.debug("A "+ ElectricalNetwork.getCableCurrent(be));
|
||||
// TFMG.LOGGER.debug("id group "+be.getData().group.id);
|
||||
// TFMG.LOGGER.debug("resistance group "+be.getData().group.resistance);
|
||||
value = Math.min(getUnit(be), range );
|
||||
|
||||
} else value = 0;
|
||||
|
||||
@@ -49,21 +49,13 @@ public class AccumulatorBlock extends DirectionalBlock implements IBE<Accumulato
|
||||
withBlockEntityDo(level, pos, be -> be.setCapacity(stack));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(BlockState p_287732_, LootParams.Builder p_287596_) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDestroyedByPlayer(BlockState state, Level level, BlockPos pos, Player player, boolean willHarvest, FluidState fluid) {
|
||||
if(!player.isCreative()&&level.getBlockEntity(pos) instanceof AccumulatorBlockEntity be) {
|
||||
@@ -80,7 +72,10 @@ public class AccumulatorBlock extends DirectionalBlock implements IBE<Accumulato
|
||||
public void onPlace(BlockState pState, Level level, BlockPos pos, BlockState pOldState, boolean pIsMoving) {
|
||||
withBlockEntityDo(level, pos, IElectric::onPlaced);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package com.drmangotea.tfmg.content.electricity.storage;
|
||||
|
||||
import com.drmangotea.tfmg.config.TFMGConfigs;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
||||
public class AccumulatorItem extends BlockItem {
|
||||
@@ -12,7 +16,6 @@ public class AccumulatorItem extends BlockItem {
|
||||
super(p_40565_, p_40566_);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isBarVisible(ItemStack p_150899_) {
|
||||
return true;
|
||||
@@ -25,7 +28,6 @@ public class AccumulatorItem extends BlockItem {
|
||||
|
||||
@Override
|
||||
public int getBarWidth(ItemStack stack) {
|
||||
|
||||
return (int) Math.min(((float) stack.getOrCreateTag().getFloat("Storage")/(float) TFMGConfigs.common().machines.accumulatorStorage.get())*13,13f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
package com.drmangotea.tfmg.content.electricity.utilities.diode;
|
||||
|
||||
import com.drmangotea.tfmg.base.TFMGDirectionalBlock;
|
||||
import com.drmangotea.tfmg.base.TFMGHorizontalDirectionalBlock;
|
||||
import com.drmangotea.tfmg.base.TFMGShapes;
|
||||
import com.drmangotea.tfmg.content.electricity.base.ConnectNeightborsPacket;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IVoltageChanger;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.drmangotea.tfmg.registry.TFMGPackets;
|
||||
import com.simibubi.create.content.decoration.encasing.EncasableBlock;
|
||||
import com.simibubi.create.foundation.block.IBE;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.DirectionalBlock;
|
||||
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.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
|
||||
public class ElectricDiodeBlock extends TFMGDirectionalBlock implements IBE<ElectricDiodeBlockEntity>, IVoltageChanger {
|
||||
public class ElectricDiodeBlock extends TFMGDirectionalBlock implements IBE<ElectricDiodeBlockEntity>, IVoltageChanger, EncasableBlock {
|
||||
public ElectricDiodeBlock(Properties p_54120_) {
|
||||
super(p_54120_);
|
||||
}
|
||||
@@ -32,11 +33,20 @@ public class ElectricDiodeBlock extends TFMGDirectionalBlock implements IBE<Elec
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
}
|
||||
@Override
|
||||
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand,
|
||||
BlockHitResult ray) {
|
||||
ItemStack heldItem = player.getItemInHand(hand);
|
||||
InteractionResult result = tryEncase(state, world, pos, heldItem, player, hand, ray);
|
||||
if (result.consumesAction())
|
||||
return result;
|
||||
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState pState, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
|
||||
return pState.getValue(FACING).getAxis().isVertical() ? TFMGShapes.RESISTOR_VERTICAL.get(pState.getValue(FACING)) : TFMGShapes.RESISTOR.get(pState.getValue(FACING));
|
||||
return pState.getValue(FACING).getAxis().isVertical() ? TFMGShapes.RESISTOR_VERTICAL.get(pState.getValue(FACING)) : TFMGShapes.POTENTIOMETER.get(pState.getValue(FACING));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,12 +2,15 @@ package com.drmangotea.tfmg.content.electricity.utilities.diode;
|
||||
|
||||
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.drmangotea.tfmg.base.TFMGHorizontalDirectionalBlock;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.content.electricity.base.UpdateInFrontPacket;
|
||||
import com.drmangotea.tfmg.content.electricity.base.VoltageAlteringBlockEntity;
|
||||
import com.drmangotea.tfmg.registry.TFMGPackets;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.block.DirectionalBlock;
|
||||
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
@@ -16,7 +19,7 @@ import static net.minecraft.world.level.block.DirectionalBlock.FACING;
|
||||
|
||||
public class ElectricDiodeBlockEntity extends VoltageAlteringBlockEntity {
|
||||
|
||||
boolean updateInFront = false;
|
||||
public boolean updateInFront = false;
|
||||
|
||||
public ElectricDiodeBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
@@ -44,7 +47,7 @@ public class ElectricDiodeBlockEntity extends VoltageAlteringBlockEntity {
|
||||
|
||||
@Override
|
||||
public float resistance() {
|
||||
Direction facing = getBlockState().getValue(FACING);
|
||||
Direction facing = getDirection();
|
||||
if (level.getBlockEntity(getBlockPos().relative(facing)) instanceof IElectric be && be.getData().getId() != data.getId()) {
|
||||
if (be.hasElectricitySlot(facing.getOpposite()))
|
||||
return Math.max(be.getNetworkResistance(), 0);
|
||||
@@ -52,9 +55,17 @@ public class ElectricDiodeBlockEntity extends VoltageAlteringBlockEntity {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Direction getDirection(){
|
||||
if(!getBlockState().hasProperty(FACING)){
|
||||
return getBlockState().getValue(TFMGHorizontalDirectionalBlock.FACING).getCounterClockWise();
|
||||
}
|
||||
|
||||
return getBlockState().getValue(FACING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasElectricitySlot(Direction direction) {
|
||||
return getBlockState().getValues().containsKey(FACING) && direction == getBlockState().getValue(FACING).getOpposite();
|
||||
return getDirection().getOpposite() == direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,10 +101,9 @@ public class ElectricDiodeBlockEntity extends VoltageAlteringBlockEntity {
|
||||
|
||||
public void updateInFront() {
|
||||
|
||||
TFMG.LOGGER.debug("IN_FRONT");
|
||||
if(!level.isClientSide)
|
||||
TFMGPackets.getChannel().send(PacketDistributor.ALL.noArg(), new UpdateInFrontPacket(BlockPos.of(getPos())));
|
||||
Direction facing = getBlockState().getValue(FACING);
|
||||
Direction facing = getBlockState().hasProperty(FACING) ? getBlockState().getValue(FACING) : getBlockState().getValue(HorizontalDirectionalBlock.FACING).getCounterClockWise();
|
||||
if (level.getBlockEntity(getBlockPos().relative(facing)) instanceof IElectric be && be.getData().getId() != data.getId()) {
|
||||
if (be.hasElectricitySlot(facing.getOpposite())) {
|
||||
be.updateNextTick();
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.drmangotea.tfmg.content.electricity.utilities.diode;
|
||||
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.drmangotea.tfmg.base.TFMGDirectionalBlock;
|
||||
import com.drmangotea.tfmg.base.TFMGShapes;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IVoltageChanger;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlocks;
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.content.decoration.encasing.EncasableBlock;
|
||||
import com.simibubi.create.content.decoration.encasing.EncasedBlock;
|
||||
import com.simibubi.create.content.equipment.wrench.IWrenchable;
|
||||
import com.simibubi.create.content.fluids.FluidTransportBehaviour;
|
||||
import com.simibubi.create.content.fluids.pipes.EncasedPipeBlock;
|
||||
import com.simibubi.create.content.kinetics.base.KineticBlockEntity;
|
||||
import com.simibubi.create.content.kinetics.base.RotatedPillarKineticBlock;
|
||||
import com.simibubi.create.foundation.block.IBE;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
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.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
public class EncasedDiodeBlock extends TFMGDirectionalBlock implements IBE<ElectricDiodeBlockEntity>, IVoltageChanger, EncasedBlock, IWrenchable {
|
||||
public EncasedDiodeBlock(Properties p_54120_) {
|
||||
super(p_54120_);
|
||||
}
|
||||
@Override
|
||||
public void onPlace(BlockState pState, Level level, BlockPos pos, BlockState pOldState, boolean pIsMoving) {
|
||||
withBlockEntityDo(level,pos, IElectric::onPlaced);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult onWrenched(BlockState state, UseOnContext context) {
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult onSneakWrenched(BlockState state, UseOnContext context) {
|
||||
if (context.getLevel().isClientSide)
|
||||
return InteractionResult.SUCCESS;
|
||||
context.getLevel()
|
||||
.levelEvent(2001, context.getClickedPos(), Block.getId(state));
|
||||
KineticBlockEntity.switchToBlockState(context.getLevel(), context.getClickedPos(),
|
||||
TFMGBlocks.DIODE.getDefaultState()
|
||||
.setValue(FACING, state.getValue(FACING)));
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEncasing(BlockState state, Level level, BlockPos pos, ItemStack heldItem, Player player, InteractionHand hand,
|
||||
BlockHitResult ray) {
|
||||
level.setBlockAndUpdate(pos, defaultBlockState().setValue(FACING,state.getValue(FACING)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ElectricDiodeBlockEntity> getBlockEntityClass() {
|
||||
return ElectricDiodeBlockEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntityType<? extends ElectricDiodeBlockEntity> getBlockEntityType() {
|
||||
return TFMGBlockEntities.DIODE.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getCasing() {
|
||||
return TFMGBlocks.HEAVY_MACHINERY_CASING.get();
|
||||
}
|
||||
}
|
||||
@@ -26,13 +26,13 @@ public class ElectricMotorBlock extends DirectionalKineticBlock implements IBE<E
|
||||
return AllShapes.MOTOR_BLOCK.get(state.getValue(FACING));
|
||||
}
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
}
|
||||
@Override
|
||||
public void onPlace(BlockState pState, Level level, BlockPos pos, BlockState pOldState, boolean pIsMoving) {
|
||||
withBlockEntityDo(level,pos, IElectric::onPlaced);
|
||||
withBlockEntityDo(level,pos, be -> be.getData().updateNextTick = true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
}
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.drmangotea.tfmg.content.electricity.utilities.electric_pump;
|
||||
|
||||
import com.drmangotea.tfmg.content.electricity.base.ConnectNeightborsPacket;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.drmangotea.tfmg.registry.TFMGPackets;
|
||||
import com.simibubi.create.content.fluids.pump.PumpBlock;
|
||||
@@ -21,13 +22,14 @@ public class ElectricPumpBlock extends PumpBlock {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onPlace(BlockState pState, Level level, BlockPos pos, BlockState pOldState, boolean pIsMoving) {
|
||||
TFMGPackets.getChannel().send(PacketDistributor.ALL.noArg(), new ConnectNeightborsPacket(pos));
|
||||
if(level.getBlockEntity(pos) instanceof ElectricPumpBlockEntity be){
|
||||
be.onPlaced();
|
||||
}
|
||||
//@Override
|
||||
//public void onPlace(BlockState pState, Level level, BlockPos pos, BlockState pOldState, boolean pIsMoving) {
|
||||
// withBlockEntityDo(level,pos, IElectric::onPlaced);
|
||||
//}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,10 +37,7 @@ public class ElectricPumpBlock extends PumpBlock {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.drmangotea.tfmg.content.electricity.utilities.electrical_switch;
|
||||
|
||||
import com.drmangotea.tfmg.base.TFMGHorizontalDirectionalBlock;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.drmangotea.tfmg.registry.TFMGPackets;
|
||||
import com.simibubi.create.foundation.block.IBE;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
|
||||
public class ElectricalSwitchBlock extends TFMGHorizontalDirectionalBlock implements IBE<ElectricalSwitchBlockEntity> {
|
||||
public ElectricalSwitchBlock(Properties p_54120_) {
|
||||
super(p_54120_);
|
||||
}
|
||||
@Override
|
||||
public void onPlace(BlockState pState, Level level, BlockPos pos, BlockState pOldState, boolean pIsMoving) {
|
||||
withBlockEntityDo(level,pos, IElectric::onPlaced);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Class<ElectricalSwitchBlockEntity> getBlockEntityClass() {
|
||||
return ElectricalSwitchBlockEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntityType<? extends ElectricalSwitchBlockEntity> getBlockEntityType() {
|
||||
return TFMGBlockEntities.ELECTRICAL_SWITCH.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.drmangotea.tfmg.content.electricity.utilities.electrical_switch;
|
||||
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.content.electricity.utilities.diode.ElectricDiodeBlockEntity;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import static net.minecraft.world.level.block.HorizontalDirectionalBlock.FACING;
|
||||
|
||||
public class ElectricalSwitchBlockEntity extends ElectricDiodeBlockEntity {
|
||||
|
||||
int signal;
|
||||
boolean signalChanged;
|
||||
|
||||
|
||||
public ElectricalSwitchBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lazyTick() {
|
||||
super.lazyTick();
|
||||
|
||||
neighbourChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if (signalChanged) {
|
||||
signalChanged = false;
|
||||
analogSignalChanged(level.getBestNeighborSignal(worldPosition));
|
||||
}
|
||||
}
|
||||
protected void analogSignalChanged(int newSignal) {
|
||||
signal = newSignal;
|
||||
updateNetwork();
|
||||
updateInFrontNextTick();
|
||||
|
||||
}
|
||||
public void neighbourChanged() {
|
||||
if (!hasLevel())
|
||||
return;
|
||||
int power = level.getBestNeighborSignal(worldPosition);
|
||||
if (power != signal)
|
||||
signalChanged = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOutputVoltage() {
|
||||
return (int) (data.getVoltage()*(signal/15f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasElectricitySlot(Direction direction) {
|
||||
return direction == getBlockState().getValue(FACING).getOpposite();
|
||||
}
|
||||
}
|
||||
@@ -50,16 +50,23 @@ public class FuseBlock extends TFMGHorizontalDirectionalBlock implements IBE<Fus
|
||||
|
||||
player.setItemInHand(hand, be.fuse);
|
||||
be.fuse = inHand;
|
||||
be.updateInFrontNextTick();
|
||||
be.updateNextTick();
|
||||
be.updateNetwork();
|
||||
be.updateInFront();
|
||||
be.sendStuff();
|
||||
return InteractionResult.SUCCESS;
|
||||
|
||||
}else
|
||||
if(inHand.isEmpty()){
|
||||
player.setItemInHand(hand, be.fuse);
|
||||
be.fuse = ItemStack.EMPTY;
|
||||
be.updateNextTick();
|
||||
be.updateNetwork();
|
||||
be.updateNetwork();
|
||||
be.updateInFront();
|
||||
be.sendStuff();
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -68,10 +75,6 @@ public class FuseBlock extends TFMGHorizontalDirectionalBlock implements IBE<Fus
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Class<FuseBlockEntity> getBlockEntityClass() {
|
||||
return FuseBlockEntity.class;
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.drmangotea.tfmg.content.electricity.utilities.fuse_block;
|
||||
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.drmangotea.tfmg.base.TFMGUtils;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.content.electricity.base.UpdateInFrontPacket;
|
||||
import com.drmangotea.tfmg.content.electricity.utilities.diode.ElectricDiodeBlockEntity;
|
||||
import com.drmangotea.tfmg.registry.TFMGPackets;
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
@@ -12,8 +15,11 @@ import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.DirectionalBlock;
|
||||
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -24,44 +30,32 @@ public class FuseBlockEntity extends ElectricDiodeBlockEntity {
|
||||
|
||||
public ItemStack fuse = ItemStack.EMPTY;
|
||||
|
||||
|
||||
public FuseBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean makeElectricityTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
|
||||
super.makeElectricityTooltip(tooltip, isPlayerSneaking);
|
||||
|
||||
if(!fuse.isEmpty())
|
||||
Lang.text("RATING "+TFMGUtils.formatUnits(fuse.getOrCreateTag().getInt("AmpRating"), "A"))
|
||||
.style(ChatFormatting.RED)
|
||||
.forGoggles(tooltip, 1);
|
||||
|
||||
|
||||
|
||||
Lang.text("CURRENT "+ getCurrent())
|
||||
.style(ChatFormatting.RED)
|
||||
.forGoggles(tooltip, 1);
|
||||
|
||||
Lang.text("USAGE "+TFMGUtils.formatUnits(getNetworkResistance(), "W"))
|
||||
.style(ChatFormatting.RED)
|
||||
.forGoggles(tooltip, 1);
|
||||
|
||||
Lang.text("VOLTAGE "+TFMGUtils.formatUnits(getData().getVoltage(), "V"))
|
||||
.style(ChatFormatting.RED)
|
||||
.forGoggles(tooltip, 1);
|
||||
|
||||
super.makeElectricityTooltip(tooltip, isPlayerSneaking);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void updateInFront(){
|
||||
public void updateInFront() {
|
||||
|
||||
|
||||
Direction facing = getBlockState().getValue(FACING);
|
||||
if (level.getBlockEntity(getBlockPos().relative(facing)) instanceof IElectric be) {
|
||||
if (be.hasElectricitySlot(facing.getCounterClockWise())) {
|
||||
if(!level.isClientSide)
|
||||
TFMGPackets.getChannel().send(PacketDistributor.ALL.noArg(), new UpdateInFrontPacket(BlockPos.of(getPos())));
|
||||
Direction facing = getBlockState().hasProperty(DirectionalBlock.FACING) ? getBlockState().getValue(DirectionalBlock.FACING) : getBlockState().getValue(FACING).getCounterClockWise();
|
||||
if (level.getBlockEntity(getBlockPos().relative(facing)) instanceof IElectric be && be.getData().getId() != data.getId()) {
|
||||
if (be.hasElectricitySlot(facing.getOpposite())) {
|
||||
be.updateNextTick();
|
||||
|
||||
}
|
||||
}
|
||||
sendStuff();
|
||||
@@ -69,28 +63,64 @@ public class FuseBlockEntity extends ElectricDiodeBlockEntity {
|
||||
}
|
||||
@Override
|
||||
public float resistance() {
|
||||
if(!hasFuse())
|
||||
return 0;
|
||||
|
||||
Direction facing = getBlockState().getValue(FACING).getCounterClockWise();
|
||||
if (level.getBlockEntity(getBlockPos().relative(facing)) instanceof IElectric be) {
|
||||
return Math.max(be.getNetworkResistance()-(be.getPowerUsage()-be.powerGeneration()),0);
|
||||
if (level.getBlockEntity(getBlockPos().relative(facing)) instanceof IElectric be && be.getData().getId() != data.getId()) {
|
||||
if (be.hasElectricitySlot(facing.getOpposite()))
|
||||
return Math.max(be.getNetworkResistance(), 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onNetworkChanged(int oldVoltage, int oldPower) {
|
||||
super.onNetworkChanged(oldVoltage, oldPower);
|
||||
|
||||
|
||||
Direction facing = getBlockState().getValue(FACING).getCounterClockWise();
|
||||
if (level.getBlockEntity(getBlockPos().relative(facing)) instanceof IElectric be)
|
||||
if(hasFuse()&&getCurrent()>=(float) fuse.getOrCreateTag().getInt("AmpRating")){
|
||||
if (level.getBlockEntity(getBlockPos().relative(facing)) instanceof IElectric be) {
|
||||
|
||||
if (hasFuse() && be.getData().highestCurrent >= (float) fuse.getOrCreateTag().getInt("AmpRating")) {
|
||||
blowFuse();
|
||||
updateNetwork();
|
||||
updateInFront();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVoltage(int newVoltage) {
|
||||
super.setVoltage(newVoltage);
|
||||
Direction facing = getBlockState().getValue(FACING).getCounterClockWise();
|
||||
if (level.getBlockEntity(getBlockPos().relative(facing)) instanceof IElectric be) {
|
||||
|
||||
if (hasFuse() && be.getData().highestCurrent >= (float) fuse.getOrCreateTag().getInt("AmpRating")) {
|
||||
blowFuse();
|
||||
updateNetwork();
|
||||
updateInFront();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
Direction facing = getBlockState().getValue(FACING).getCounterClockWise();
|
||||
if (level.getBlockEntity(getBlockPos().relative(facing)) instanceof IElectric be) {
|
||||
// TFMG.LOGGER.debug("AMPS " + be.getData().highestCurrent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNextTick() {
|
||||
super.updateNextTick();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -112,6 +142,7 @@ public class FuseBlockEntity extends ElectricDiodeBlockEntity {
|
||||
level.random.nextFloat() * 0.4F + 0.8F);
|
||||
fuse = ItemStack.EMPTY;
|
||||
TFMGUtils.spawnElectricParticles(level,getBlockPos());
|
||||
sendStuff();
|
||||
|
||||
}
|
||||
|
||||
@@ -120,6 +151,13 @@ public class FuseBlockEntity extends ElectricDiodeBlockEntity {
|
||||
return direction == getBlockState().getValue(FACING).getClockWise();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addToTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
|
||||
|
||||
super.addToTooltip(tooltip, isPlayerSneaking);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void write(CompoundTag compound, boolean clientPacket) {
|
||||
super.write(compound, clientPacket);
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.drmangotea.tfmg.content.electricity.utilities.fuse_block;
|
||||
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FuseItem extends Item{
|
||||
|
||||
|
||||
public FuseItem(Properties p_41383_) {
|
||||
super(p_41383_);
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void appendHoverText(ItemStack stack, Level world, List<Component> tooltip, TooltipFlag flag) {
|
||||
|
||||
tooltip.add(Lang.translateDirect("tooltip.fuse", stack.getOrCreateTag().getInt("AmpRating")).append("A")
|
||||
.withStyle(ChatFormatting.GREEN)
|
||||
);
|
||||
|
||||
|
||||
super.appendHoverText(stack, world, tooltip, flag);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.drmangotea.tfmg.content.electricity.utilities.polarizer;
|
||||
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.drmangotea.tfmg.base.TFMGUtils;
|
||||
import com.drmangotea.tfmg.registry.TFMGItems;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.event.entity.EntityStruckByLightningEvent;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
||||
|
||||
@EventBusSubscriber
|
||||
public class PolarizeByLightningEvent {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onStruckByLightning(EntityStruckByLightningEvent event) {
|
||||
|
||||
if (event.getEntity() instanceof ItemEntity entity) {
|
||||
if (entity.getItem().is(TFMGItems.MAGNETIC_ALLOY_INGOT.get())) {
|
||||
|
||||
int random = entity.level().random.nextInt(entity.getItem().getCount()+1);
|
||||
|
||||
if(random == 1){
|
||||
if(entity.level().random.nextBoolean()){
|
||||
random =0;
|
||||
}else {
|
||||
random =1;
|
||||
}
|
||||
}
|
||||
|
||||
entity.setItem(new ItemStack(TFMGItems.MAGNET,random));
|
||||
TFMGUtils.spawnElectricParticles(entity.level(), entity.blockPosition());
|
||||
event.setCanceled(true);
|
||||
}
|
||||
if (entity.getItem().is(TFMGItems.MAGNET.get())) {
|
||||
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package com.drmangotea.tfmg.content.electricity.utilities.polarizer;
|
||||
import com.drmangotea.tfmg.base.TFMGHorizontalDirectionalBlock;
|
||||
import com.drmangotea.tfmg.base.TFMGShapes;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.content.machinery.misc.winding_machine.SpoolItem;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.simibubi.create.foundation.block.IBE;
|
||||
import net.minecraft.core.BlockPos;
|
||||
@@ -51,6 +50,7 @@ public class PolarizerBlock extends TFMGHorizontalDirectionalBlock implements IB
|
||||
public void onPlace(BlockState pState, Level level, BlockPos pos, BlockState pOldState, boolean pIsMoving) {
|
||||
withBlockEntityDo(level,pos, IElectric::onPlaced);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.drmangotea.tfmg.registry.TFMGRecipeTypes;
|
||||
import com.simibubi.create.content.processing.sequenced.SequencedAssemblyRecipe;
|
||||
import com.simibubi.create.foundation.item.SmartInventory;
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
import com.simibubi.create.foundation.utility.animation.LerpedFloat;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
@@ -35,12 +36,11 @@ public class PolarizerBlockEntity extends ElectricBlockEntity {
|
||||
.whenContentsChanged(this::onInventoryChanged);
|
||||
public LazyOptional<IItemHandlerModifiable> itemCapability;
|
||||
|
||||
LerpedFloat angle = LerpedFloat.angular();
|
||||
|
||||
public boolean shouldChargeItem = false;
|
||||
|
||||
public boolean chargeCapacitors = false;
|
||||
|
||||
public int capacitorPercentage = 0;
|
||||
|
||||
boolean charged = false;
|
||||
|
||||
public PolarizerBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
@@ -54,9 +54,10 @@ public class PolarizerBlockEntity extends ElectricBlockEntity {
|
||||
}
|
||||
|
||||
public void onInventoryChanged(int count) {
|
||||
if(inventory.isEmpty()) {
|
||||
if (inventory.isEmpty()) {
|
||||
shouldChargeItem = false;
|
||||
chargeCapacitors = false;
|
||||
updateNextTick();
|
||||
return;
|
||||
}
|
||||
ItemStack itemStack = inventory.getItem(0);
|
||||
@@ -64,55 +65,70 @@ public class PolarizerBlockEntity extends ElectricBlockEntity {
|
||||
if (getRecipe(itemStack).isPresent()) {
|
||||
shouldChargeItem = false;
|
||||
chargeCapacitors = true;
|
||||
if (capacitorPercentage == 100) {
|
||||
updateNextTick();
|
||||
if (capacitorPercentage == 200) {
|
||||
performRecipe(getRecipe(itemStack).get());
|
||||
}
|
||||
} else if (itemStack.getCapability(ForgeCapabilities.ENERGY).isPresent()) {
|
||||
shouldChargeItem = true;
|
||||
chargeCapacitors = false;
|
||||
updateNextTick();
|
||||
} else {
|
||||
shouldChargeItem = false;
|
||||
chargeCapacitors = false;
|
||||
updateNextTick();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//@Override
|
||||
//public boolean canBeInGroups() {
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
@Override
|
||||
public float resistance() {
|
||||
return chargeCapacitors ? 30 : 0;
|
||||
}
|
||||
|
||||
//
|
||||
@Override
|
||||
public boolean addToTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
|
||||
|
||||
Lang.number((double) capacitorPercentage / 2f).forGoggles(tooltip);
|
||||
if (chargeCapacitors)
|
||||
Lang.text("CAPACITOR").forGoggles(tooltip);
|
||||
if (shouldChargeItem)
|
||||
Lang.text("ITEM").forGoggles(tooltip);
|
||||
|
||||
super.addToTooltip(tooltip, isPlayerSneaking);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeInGroups() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float resistance() {
|
||||
return chargeCapacitors ? 1500 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addToTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
|
||||
|
||||
Lang.number(capacitorPercentage).forGoggles(tooltip);
|
||||
if (chargeCapacitors)
|
||||
Lang.text("CAPACITOR").forGoggles(tooltip);
|
||||
if (shouldChargeItem)
|
||||
Lang.text("ITEM").forGoggles(tooltip);
|
||||
|
||||
return super.addToTooltip(tooltip, isPlayerSneaking);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (level.isClientSide) {
|
||||
angle.chase(180 * (capacitorPercentage / 200f), 0.2f, LerpedFloat.Chaser.EXP);
|
||||
angle.tickChaser();
|
||||
}
|
||||
if (!networkUndersupplied())
|
||||
if (chargeCapacitors)
|
||||
if (!charged) {
|
||||
if (capacitorPercentage < 100) {
|
||||
capacitorPercentage++;
|
||||
} else onInventoryChanged(inventory.getStackInSlot(0).getCount());
|
||||
if (getPowerUsage() > 5000)
|
||||
if (chargeCapacitors)
|
||||
if (!charged) {
|
||||
if (capacitorPercentage < 200) {
|
||||
capacitorPercentage++;
|
||||
} else onInventoryChanged(inventory.getStackInSlot(0).getCount());
|
||||
|
||||
charged = true;
|
||||
} else charged = false;
|
||||
|
||||
charged = true;
|
||||
} else charged = false;
|
||||
}
|
||||
|
||||
public void performRecipe(PolarizingRecipe recipe) {
|
||||
@@ -129,7 +145,7 @@ public class PolarizerBlockEntity extends ElectricBlockEntity {
|
||||
if (assemblyRecipe.isPresent()) {
|
||||
return assemblyRecipe;
|
||||
} else {
|
||||
// inventory.setItem(0, item);
|
||||
// inventory.setItem(0, item);
|
||||
return TFMGRecipeTypes.POLARIZING.find(inventory, this.level);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package com.drmangotea.tfmg.content.electricity.utilities.polarizer;
|
||||
|
||||
import com.drmangotea.tfmg.registry.TFMGPartialModels;
|
||||
import com.jozufozu.flywheel.util.transform.TransformStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.simibubi.create.foundation.blockEntity.renderer.SafeBlockEntityRenderer;
|
||||
import com.simibubi.create.foundation.render.CachedBufferer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.client.renderer.entity.ItemRenderer;
|
||||
import net.minecraft.core.Direction;
|
||||
@@ -13,6 +17,9 @@ import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import static com.simibubi.create.content.kinetics.base.HorizontalKineticBlock.HORIZONTAL_FACING;
|
||||
import static net.minecraft.world.level.block.HorizontalDirectionalBlock.FACING;
|
||||
|
||||
public class PolarizerRenderer extends SafeBlockEntityRenderer<PolarizerBlockEntity> {
|
||||
|
||||
public PolarizerRenderer(BlockEntityRendererProvider.Context context) {}
|
||||
@@ -20,16 +27,28 @@ public class PolarizerRenderer extends SafeBlockEntityRenderer<PolarizerBlockEnt
|
||||
@Override
|
||||
protected void renderSafe(PolarizerBlockEntity be, float partialTicks, PoseStack ms, MultiBufferSource buffer,
|
||||
int light, int overlay) {
|
||||
BlockState blockState = be.getBlockState();
|
||||
VertexConsumer vb = buffer.getBuffer(RenderType.solid());
|
||||
CachedBufferer.partial(TFMGPartialModels.POLARIZER_DIAL,blockState)
|
||||
.centre()
|
||||
.rotateY(blockState.getValue(FACING).getAxis() == Direction.Axis.Z ? Math.abs(blockState.getValue(FACING).toYRot() - 180) : blockState.getValue(FACING).toYRot())
|
||||
.translateY(-0.025)
|
||||
.rotateZ(be.angle.getValue(partialTicks))
|
||||
.translateX(0.05)
|
||||
.unCentre()
|
||||
.renderInto(ms, vb);
|
||||
ItemStack heldItem = be.inventory.getItem(0);
|
||||
if (heldItem.isEmpty())
|
||||
return;
|
||||
BlockState blockState = be.getBlockState();
|
||||
|
||||
ItemRenderer itemRenderer = Minecraft.getInstance()
|
||||
.getItemRenderer();
|
||||
boolean blockItem = itemRenderer.getModel(heldItem, null, null, 0)
|
||||
.isGui3d();
|
||||
|
||||
ms.pushPose();
|
||||
|
||||
|
||||
TransformStack msr = TransformStack.cast(ms)
|
||||
.centre()
|
||||
.rotateY(blockState.getValue(HorizontalDirectionalBlock.FACING).getAxis()== Direction.Axis.X ? 90 : 0)
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.drmangotea.tfmg.content.electricity.utilities.potentiometer;
|
||||
|
||||
import com.drmangotea.tfmg.base.TFMGDirectionalBlock;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IVoltageChanger;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlocks;
|
||||
import com.simibubi.create.content.decoration.encasing.EncasedBlock;
|
||||
import com.simibubi.create.content.equipment.wrench.IWrenchable;
|
||||
import com.simibubi.create.content.kinetics.base.KineticBlockEntity;
|
||||
import com.simibubi.create.foundation.block.IBE;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
|
||||
public class EncasedPotentiometerBlock extends TFMGDirectionalBlock implements IBE<PotentiometerBlockEntity>, IVoltageChanger, EncasedBlock, IWrenchable {
|
||||
public EncasedPotentiometerBlock(Properties p_54120_) {
|
||||
super(p_54120_);
|
||||
}
|
||||
@Override
|
||||
public void onPlace(BlockState pState, Level level, BlockPos pos, BlockState pOldState, boolean pIsMoving) {
|
||||
withBlockEntityDo(level,pos, IElectric::onPlaced);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
}
|
||||
@Override
|
||||
public InteractionResult onWrenched(BlockState state, UseOnContext context) {
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult onSneakWrenched(BlockState state, UseOnContext context) {
|
||||
if (context.getLevel().isClientSide)
|
||||
return InteractionResult.SUCCESS;
|
||||
context.getLevel()
|
||||
.levelEvent(2001, context.getClickedPos(), Block.getId(state));
|
||||
KineticBlockEntity.switchToBlockState(context.getLevel(), context.getClickedPos(),
|
||||
TFMGBlocks.POTENTIOMETER.getDefaultState()
|
||||
.setValue(FACING, state.getValue(FACING)));
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleEncasing(BlockState state, Level level, BlockPos pos, ItemStack heldItem, Player player, InteractionHand hand,
|
||||
BlockHitResult ray) {
|
||||
level.setBlockAndUpdate(pos, this.defaultBlockState().setValue(FACING,state.getValue(FACING)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<PotentiometerBlockEntity> getBlockEntityClass() {
|
||||
return PotentiometerBlockEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntityType<? extends PotentiometerBlockEntity> getBlockEntityType() {
|
||||
return TFMGBlockEntities.POTENTIOMETER.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getCasing() {
|
||||
return TFMGBlocks.HEAVY_MACHINERY_CASING.get();
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,22 @@ import com.drmangotea.tfmg.base.TFMGShapes;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IVoltageChanger;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.simibubi.create.content.decoration.encasing.EncasableBlock;
|
||||
import com.simibubi.create.foundation.block.IBE;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
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.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
public class PotentiometerBlock extends TFMGDirectionalBlock implements IBE<PotentiometerBlockEntity>, IVoltageChanger {
|
||||
public class PotentiometerBlock extends TFMGDirectionalBlock implements IBE<PotentiometerBlockEntity>, IVoltageChanger, EncasableBlock {
|
||||
public PotentiometerBlock(Properties p_54120_) {
|
||||
super(p_54120_);
|
||||
}
|
||||
@@ -27,11 +33,20 @@ public class PotentiometerBlock extends TFMGDirectionalBlock implements IBE<Pote
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
}
|
||||
@Override
|
||||
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand,
|
||||
BlockHitResult ray) {
|
||||
ItemStack heldItem = player.getItemInHand(hand);
|
||||
InteractionResult result = tryEncase(state, world, pos, heldItem, player, hand, ray);
|
||||
if (result.consumesAction())
|
||||
return result;
|
||||
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState pState, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
|
||||
return pState.getValue(FACING).getAxis().isVertical() ? TFMGShapes.RESISTOR_VERTICAL.get(pState.getValue(FACING)) : TFMGShapes.RESISTOR.get(pState.getValue(FACING));
|
||||
return pState.getValue(FACING).getAxis().isVertical() ? TFMGShapes.RESISTOR_VERTICAL.get(pState.getValue(FACING)) : TFMGShapes.POTENTIOMETER.get(pState.getValue(FACING));
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +57,6 @@ public class PotentiometerBlock extends TFMGDirectionalBlock implements IBE<Pote
|
||||
|
||||
@Override
|
||||
public BlockEntityType<? extends PotentiometerBlockEntity> getBlockEntityType() {
|
||||
return TFMGBlockEntities.RESISTOR.get();
|
||||
return TFMGBlockEntities.POTENTIOMETER.get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.drmangotea.tfmg.content.electricity.utilities.resistor;
|
||||
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.drmangotea.tfmg.base.TFMGShapes;
|
||||
import com.drmangotea.tfmg.base.WallMountBlock;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlocks;
|
||||
import com.simibubi.create.foundation.block.IBE;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.storage.loot.LootParams;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ResistorBlock extends WallMountBlock implements IBE<ResistorBlockEntity> {
|
||||
public ResistorBlock(Properties p_49795_) {
|
||||
super(p_49795_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlacedBy(Level level, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
|
||||
super.setPlacedBy(level, pos, state, placer, stack);
|
||||
withBlockEntityDo(level, pos, be -> be.setResistance(stack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(BlockState p_287732_, LootParams.Builder p_287596_) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@Override
|
||||
public boolean onDestroyedByPlayer(BlockState state, Level level, BlockPos pos, Player player, boolean willHarvest, FluidState fluid) {
|
||||
if(!player.isCreative()&&level.getBlockEntity(pos) instanceof ResistorBlockEntity be) {
|
||||
ItemStack item = TFMGBlocks.RESISTOR.asItem().getDefaultInstance();
|
||||
item.getOrCreateTag().putInt("Resistance", be.resistance);
|
||||
ItemEntity itemToSpawn = new ItemEntity((Level) level, pos.getX() + 0.5f, pos.getY() + 0.5f, pos.getZ() + 0.5f, item);
|
||||
if (itemToSpawn.getItem().getCount() > 0)
|
||||
level.addFreshEntity(itemToSpawn);
|
||||
}
|
||||
return super.onDestroyedByPlayer(state, level, pos, player, willHarvest, fluid);
|
||||
}
|
||||
|
||||
//
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState p_60555_, BlockGetter p_60556_, BlockPos p_60557_, CollisionContext p_60558_) {
|
||||
return TFMGShapes.RESISTOR.get(p_60555_.getValue(FACING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlace(BlockState pState, Level level, BlockPos pos, BlockState pOldState, boolean pIsMoving) {
|
||||
withBlockEntityDo(level,pos, IElectric::onPlaced);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ResistorBlockEntity> getBlockEntityClass() {
|
||||
return ResistorBlockEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntityType<? extends ResistorBlockEntity> getBlockEntityType() {
|
||||
return TFMGBlockEntities.RESISTOR.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.drmangotea.tfmg.content.electricity.utilities.resistor;
|
||||
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.drmangotea.tfmg.content.electricity.base.ElectricBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import static com.drmangotea.tfmg.base.WallMountBlock.FACING;
|
||||
|
||||
public class ResistorBlockEntity extends ElectricBlockEntity {
|
||||
|
||||
public int resistance = 500;
|
||||
|
||||
public ResistorBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasElectricitySlot(Direction direction) {
|
||||
return direction == getBlockState().getValue(FACING).getOpposite();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeInGroups() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float resistance() {
|
||||
return resistance;
|
||||
}
|
||||
|
||||
public void setResistance(ItemStack stack){
|
||||
TFMG.LOGGER.debug("Resistohr "+stack.getOrCreateTag().getInt("Resistance"));
|
||||
this.resistance = stack.getOrCreateTag().getInt("Resistance");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void write(CompoundTag compound, boolean clientPacket) {
|
||||
super.write(compound, clientPacket);
|
||||
compound.putInt("Resistance",resistance);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void read(CompoundTag compound, boolean clientPacket) {
|
||||
super.read(compound, clientPacket);
|
||||
resistance = compound.getInt("Resistance");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.drmangotea.tfmg.content.electricity.utilities.resistor;
|
||||
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ResistorBlockItem extends BlockItem {
|
||||
public ResistorBlockItem(Block p_40565_, Properties p_40566_) {
|
||||
super(p_40565_, p_40566_);
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void appendHoverText(ItemStack stack, Level world, List<Component> tooltip, TooltipFlag flag) {
|
||||
tooltip.add(Lang.translateDirect("tooltip.resistor", stack.getOrCreateTag().getInt("Resistance")).append("Ω")
|
||||
.withStyle(ChatFormatting.GREEN)
|
||||
);
|
||||
super.appendHoverText(stack, world, tooltip, flag);
|
||||
}
|
||||
}
|
||||
@@ -40,11 +40,6 @@ public class SegmentedDisplayBlockEntity extends ElectricBlockEntity {
|
||||
color = DyeColor.LIME;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void setColor(DyeColor color) {
|
||||
|
||||
|
||||
@@ -57,32 +52,20 @@ public class SegmentedDisplayBlockEntity extends ElectricBlockEntity {
|
||||
|
||||
@Override
|
||||
public float resistance() {
|
||||
|
||||
if(segmentsToRender.isEmpty()&&segmentsToRender2.isEmpty())
|
||||
return 0;
|
||||
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lazyTick() {
|
||||
super.lazyTick();
|
||||
|
||||
|
||||
if(getData().getVoltage()<10||getPowerUsage()<5){
|
||||
if(getPowerUsage()<5){
|
||||
segmentsToRender = new ArrayList<>();
|
||||
segmentsToRender2 = new ArrayList<>();
|
||||
}else {
|
||||
|
||||
segmentsToRender = getSegments();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void clearCustomText() {
|
||||
partIndex = 0;
|
||||
customText = Optional.empty();
|
||||
@@ -162,16 +145,16 @@ public class SegmentedDisplayBlockEntity extends ElectricBlockEntity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(CompoundTag nbt, boolean clientPacket) {
|
||||
super.read(nbt, clientPacket);
|
||||
color = NBTHelper.readEnum(nbt,"color",DyeColor.class);
|
||||
if (nbt.contains("CustomText")) {
|
||||
public void read(CompoundTag compound, boolean clientPacket) {
|
||||
super.read(compound, clientPacket);
|
||||
color = NBTHelper.readEnum(compound,"color",DyeColor.class);
|
||||
if (compound.contains("CustomText")) {
|
||||
DynamicComponent component = customText.orElseGet(DynamicComponent::new);
|
||||
component.read(level, worldPosition, nbt);
|
||||
component.read(level, worldPosition, compound);
|
||||
|
||||
if (component.isValid()) {
|
||||
customText = Optional.of(component);
|
||||
partIndex = nbt.getInt("CustomTextIndex");
|
||||
partIndex = compound.getInt("CustomTextIndex");
|
||||
} else {
|
||||
customText = Optional.empty();
|
||||
partIndex = 0;
|
||||
@@ -182,16 +165,18 @@ public class SegmentedDisplayBlockEntity extends ElectricBlockEntity {
|
||||
updateDisplayedStrings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(CompoundTag nbt, boolean clientPacket) {
|
||||
super.write(nbt, clientPacket);
|
||||
|
||||
NBTHelper.writeEnum(nbt,"color",color);
|
||||
|
||||
@Override
|
||||
public void write(CompoundTag compound, boolean clientPacket) {
|
||||
super.write(compound, clientPacket);
|
||||
|
||||
NBTHelper.writeEnum(compound,"color",color);
|
||||
|
||||
if (customText.isPresent()) {
|
||||
nbt.putInt("CustomTextIndex", partIndex);
|
||||
compound.putInt("CustomTextIndex", partIndex);
|
||||
customText.get()
|
||||
.write(nbt);
|
||||
.write(compound);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ public class SegmentedDisplayRenderer extends SafeBlockEntityRenderer<SegmentedD
|
||||
|
||||
//
|
||||
put(0,1,2,3,5,6,7);
|
||||
put(1,7,6);
|
||||
put(1,1,2);
|
||||
put(2,3,6,4,2,5);
|
||||
put(3,3,4,5,6,7);
|
||||
put(4,1,4,6,7);
|
||||
@@ -82,7 +82,7 @@ public class SegmentedDisplayRenderer extends SafeBlockEntityRenderer<SegmentedD
|
||||
put("e",1,2,3,4,5);
|
||||
put("f",1,2,3,4);
|
||||
put("g",1,2,3,5,7);
|
||||
put("h",1,2,4,5,7);
|
||||
put("h",1,2,4,6,7);
|
||||
put("i",1,2);
|
||||
put("j",6,7,5,2);
|
||||
put("k",1,2,9,10);
|
||||
|
||||
@@ -1,11 +1,28 @@
|
||||
package com.drmangotea.tfmg.content.electricity.utilities.transformer;
|
||||
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ElectromagneticCoilItem extends Item {
|
||||
public ElectromagneticCoilItem(Properties p_41383_) {
|
||||
super(p_41383_);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void appendHoverText(ItemStack stack, Level world, List<Component> tooltip, TooltipFlag flag) {
|
||||
tooltip.add(Lang.translateDirect("tooltip.coils", stack.getOrCreateTag().getInt("Turns"))
|
||||
.withStyle(ChatFormatting.GREEN)
|
||||
);
|
||||
super.appendHoverText(stack, world, tooltip, flag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package com.drmangotea.tfmg.content.electricity.utilities.transformer;
|
||||
import com.drmangotea.tfmg.base.TFMGHorizontalDirectionalBlock;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IVoltageChanger;
|
||||
import com.drmangotea.tfmg.content.machinery.misc.winding_machine.SpoolItem;
|
||||
import com.drmangotea.tfmg.content.machinery.misc.winding_machine.WindingMachineBlockEntity;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.drmangotea.tfmg.registry.TFMGItems;
|
||||
import com.simibubi.create.foundation.block.IBE;
|
||||
|
||||
@@ -91,16 +91,16 @@ public class TransformerBlockEntity extends VoltageAlteringBlockEntity {
|
||||
|
||||
@Override
|
||||
public float resistance() {
|
||||
if(coilRatio == 0)
|
||||
return 0;
|
||||
|
||||
Direction facing = getBlockState().getValue(FACING);
|
||||
if (level.getBlockEntity(getBlockPos().relative(facing)) instanceof IElectric be) {
|
||||
return Math.max(be.getNetworkResistance(),0);
|
||||
Direction facing = getBlockState().getValue(FACING).getCounterClockWise();
|
||||
if (level.getBlockEntity(getBlockPos().relative(facing)) instanceof IElectric be && be.getData().getId() != data.getId()) {
|
||||
if (be.hasElectricitySlot(facing.getOpposite()))
|
||||
return Math.max(be.getNetworkResistance(), 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getPowerUsage() {
|
||||
return (int) ((float)super.getPowerUsage()* coilRatio);
|
||||
}
|
||||
@Override
|
||||
public boolean hasElectricitySlot(Direction direction) {
|
||||
return direction == getBlockState().getValue(FACING).getClockWise();
|
||||
@@ -109,7 +109,7 @@ public class TransformerBlockEntity extends VoltageAlteringBlockEntity {
|
||||
public void onNetworkChanged(int oldVoltage, int oldPower) {
|
||||
super.onNetworkChanged(oldVoltage, oldPower);
|
||||
|
||||
if(oldVoltage != getData().getVoltage()||oldPower != getPowerUsage()) {
|
||||
if (oldVoltage != getData().getVoltage() || oldPower != getPowerUsage()) {
|
||||
updateInFront = true;
|
||||
}
|
||||
sendStuff();
|
||||
|
||||
@@ -1,23 +1,13 @@
|
||||
package com.drmangotea.tfmg.content.electricity.utilities.transformer;
|
||||
|
||||
import com.drmangotea.tfmg.content.machinery.misc.winding_machine.SpoolItem;
|
||||
import com.drmangotea.tfmg.content.machinery.misc.winding_machine.WindingMachineBlockEntity;
|
||||
import com.drmangotea.tfmg.registry.TFMGPartialModels;
|
||||
import com.drmangotea.tfmg.registry.TFMGTags;
|
||||
import com.jozufozu.flywheel.util.transform.TransformStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.simibubi.create.foundation.blockEntity.renderer.SafeBlockEntityRenderer;
|
||||
import com.simibubi.create.foundation.render.CachedBufferer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.client.renderer.entity.ItemRenderer;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import static com.simibubi.create.content.kinetics.base.HorizontalKineticBlock.HORIZONTAL_FACING;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.drmangotea.tfmg.content.electricity.utilities.transistor;
|
||||
|
||||
import com.drmangotea.tfmg.base.TFMGHorizontalDirectionalBlock;
|
||||
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
|
||||
import com.simibubi.create.foundation.block.IBE;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class TransistorBlock extends TFMGHorizontalDirectionalBlock implements IBE<TransistorBlockEntity> {
|
||||
public TransistorBlock(Properties p_54120_) {
|
||||
super(p_54120_);
|
||||
}
|
||||
@Override
|
||||
public void onPlace(BlockState pState, Level level, BlockPos pos, BlockState pOldState, boolean pIsMoving) {
|
||||
withBlockEntityDo(level,pos, IElectric::onPlaced);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
IBE.onRemove(state, level, pos, newState);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Class<TransistorBlockEntity> getBlockEntityClass() {
|
||||
return TransistorBlockEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntityType<? extends TransistorBlockEntity> getBlockEntityType() {
|
||||
return TFMGBlockEntities.TRANSISTOR.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.drmangotea.tfmg.content.electricity.utilities.transistor;
|
||||
|
||||
import com.drmangotea.tfmg.content.electricity.utilities.diode.ElectricDiodeBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import static net.minecraft.world.level.block.HorizontalDirectionalBlock.FACING;
|
||||
|
||||
public class TransistorBlockEntity extends ElectricDiodeBlockEntity {
|
||||
|
||||
|
||||
|
||||
public TransistorBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
}
|
||||
|
||||
|
||||
public int findBestVoltage(){
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOutputVoltage() {
|
||||
return (int) (data.getVoltage()*(findBestVoltage()/100f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasElectricitySlot(Direction direction) {
|
||||
return direction == getBlockState().getValue(FACING).getOpposite();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.drmangotea.tfmg.content.engines;
|
||||
|
||||
import com.drmangotea.tfmg.content.items.weapons.flamethrover.FlamethrowerItem;
|
||||
import com.drmangotea.tfmg.registry.TFMGItems;
|
||||
import com.simibubi.create.content.fluids.tank.FluidTankBlockEntity;
|
||||
import com.tterrag.registrate.util.entry.FluidEntry;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
|
||||
public class FluidContainingItem extends Item {
|
||||
|
||||
public final FluidEntry<?> fluid;
|
||||
|
||||
public static final int CAPACITY = 4000;
|
||||
|
||||
public FluidContainingItem(Properties p_41383_, FluidEntry<?> fluid) {
|
||||
super(p_41383_);
|
||||
this.fluid = fluid;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public InteractionResult useOn(UseOnContext context) {
|
||||
|
||||
Level level = context.getLevel();
|
||||
BlockPos pos = context.getClickedPos();
|
||||
ItemStack stack = context.getItemInHand();
|
||||
CompoundTag nbt = stack.getOrCreateTag();
|
||||
|
||||
if (context.getPlayer().isShiftKeyDown()&&nbt.getInt("amount")>0) {
|
||||
|
||||
level.playSound(null, pos, SoundEvents.BUCKET_FILL, SoundSource.BLOCKS, 1f, 1f);
|
||||
nbt.putInt("amount", 0);
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
if (level.getBlockEntity(pos) != null)
|
||||
if (level.getBlockEntity(pos) instanceof FluidTankBlockEntity fluidTankBe) {
|
||||
|
||||
FluidTankBlockEntity be = fluidTankBe.isController() ? fluidTankBe : fluidTankBe.getControllerBE();
|
||||
|
||||
if (be.getFluid(0).getFluid().isSame(fluid.get())) {
|
||||
|
||||
int toDrain = Math.min(CAPACITY - nbt.getInt("amount"), be.getFluid(0).getAmount());
|
||||
if(toDrain == 0||context.getPlayer().getCooldowns().isOnCooldown(stack.getItem()))
|
||||
return InteractionResult.PASS;
|
||||
level.playSound(null, be.getBlockPos(), SoundEvents.BUCKET_FILL, SoundSource.BLOCKS, 1f, 1f);
|
||||
be.getTankInventory().drain(toDrain, IFluidHandler.FluidAction.EXECUTE);
|
||||
nbt.putInt("amount", nbt.getInt("amount") + toDrain);
|
||||
context.getPlayer().getCooldowns().addCooldown(stack.getItem(), 20);
|
||||
|
||||
|
||||
|
||||
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.drmangotea.tfmg.content.engines;
|
||||
package com.drmangotea.tfmg.content.engines.base;
|
||||
|
||||
import com.drmangotea.tfmg.TFMG;
|
||||
import com.drmangotea.tfmg.base.TFMGUtils;
|
||||
import com.drmangotea.tfmg.config.TFMGConfigs;
|
||||
import com.drmangotea.tfmg.content.engines.FluidContainingItem;
|
||||
import com.drmangotea.tfmg.content.engines.regular_engine.RegularEngineBlockEntity;
|
||||
import com.drmangotea.tfmg.registry.TFMGFluids;
|
||||
import com.drmangotea.tfmg.registry.TFMGItems;
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.content.kinetics.base.KineticBlockEntity;
|
||||
@@ -16,8 +18,11 @@ import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
@@ -35,24 +40,32 @@ import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.drmangotea.tfmg.content.engines.EngineBlock.ENGINE_STATE;
|
||||
import static com.drmangotea.tfmg.content.engines.EngineBlock.EngineState.NORMAL;
|
||||
import static com.drmangotea.tfmg.content.engines.EngineBlock.EngineState.SHAFT;
|
||||
import static com.drmangotea.tfmg.content.engines.base.EngineBlock.ENGINE_STATE;
|
||||
import static com.drmangotea.tfmg.content.engines.base.EngineBlock.EngineState.NORMAL;
|
||||
import static com.drmangotea.tfmg.content.engines.base.EngineBlock.EngineState.SHAFT;
|
||||
import static com.simibubi.create.content.kinetics.base.HorizontalKineticBlock.HORIZONTAL_FACING;
|
||||
|
||||
public abstract class AbstractEngineBlockEntity extends KineticBlockEntity {
|
||||
|
||||
//
|
||||
EngineComponentsInventory componentsInventory;
|
||||
FluidTank fuelTank;
|
||||
FluidTank exhaustTank;
|
||||
LazyOptional<IFluidHandler> fluidCapability;
|
||||
public EngineComponentsInventory componentsInventory;
|
||||
public FluidTank fuelTank;
|
||||
public FluidTank exhaustTank;
|
||||
public LazyOptional<IFluidHandler> fluidCapability;
|
||||
//
|
||||
BlockPos controller = getBlockPos();
|
||||
public BlockPos controller = getBlockPos();
|
||||
boolean connectNextTick = true;
|
||||
List<Long> engines = new ArrayList<>();
|
||||
int engineNumber = 0;
|
||||
//
|
||||
int oil = 0;
|
||||
int coolingFluid =0;
|
||||
//
|
||||
float rpm =0;
|
||||
float fuelInjectionRate = 0;
|
||||
//
|
||||
int signal;
|
||||
boolean signalChanged;
|
||||
|
||||
|
||||
public AbstractEngineBlockEntity(BlockEntityType<?> typeIn, BlockPos pos, BlockState state) {
|
||||
@@ -72,6 +85,21 @@ public abstract class AbstractEngineBlockEntity extends KineticBlockEntity {
|
||||
setChanged();
|
||||
}
|
||||
|
||||
public boolean hasAllComponents(){
|
||||
|
||||
if(level.getBlockEntity(controller) instanceof AbstractEngineBlockEntity be){
|
||||
return be.nextComponent() == Ingredient.EMPTY;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lazyTick() {
|
||||
super.lazyTick();
|
||||
neighbourChanged();
|
||||
}
|
||||
|
||||
public Ingredient nextComponent() {
|
||||
if (!isController())
|
||||
return Ingredient.EMPTY;
|
||||
@@ -84,6 +112,25 @@ public abstract class AbstractEngineBlockEntity extends KineticBlockEntity {
|
||||
return Ingredient.EMPTY;
|
||||
}
|
||||
|
||||
public void onUpdated(){}
|
||||
|
||||
public void updateRotation(){
|
||||
|
||||
if(!canWork()||!isController()){
|
||||
rpm = 0;
|
||||
return;
|
||||
}
|
||||
rpm = 4000*speedModifier()*fuelInjectionRate;
|
||||
|
||||
}
|
||||
public boolean canWork(){
|
||||
|
||||
if(!nextComponent().isEmpty())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
@@ -93,6 +140,32 @@ public abstract class AbstractEngineBlockEntity extends KineticBlockEntity {
|
||||
connect();
|
||||
connectNextTick = false;
|
||||
}
|
||||
if (signalChanged) {
|
||||
signalChanged = false;
|
||||
analogSignalChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected void analogSignalChanged() {
|
||||
|
||||
int newSignal = level.getBestNeighborSignal(controller);
|
||||
|
||||
for(long posLong : engines){
|
||||
BlockPos pos = BlockPos.of(posLong);
|
||||
newSignal = Math.max(level.getBestNeighborSignal(pos), newSignal);
|
||||
|
||||
}
|
||||
if(isController()){
|
||||
signal = newSignal;
|
||||
fuelInjectionRate = signal / 15f;
|
||||
updateRotation();
|
||||
}
|
||||
if(level.getBlockEntity(controller) instanceof AbstractEngineBlockEntity be) {
|
||||
|
||||
be.signal = newSignal;
|
||||
be.fuelInjectionRate = signal / 15f;
|
||||
be.updateRotation();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract int effectiveSpeed();
|
||||
@@ -131,7 +204,7 @@ public abstract class AbstractEngineBlockEntity extends KineticBlockEntity {
|
||||
return TFMGConfigs.common().machines.engineMaxLength.get();
|
||||
}
|
||||
|
||||
public boolean insertItem(ItemStack itemStack, boolean shifting) {
|
||||
public boolean insertItem(ItemStack itemStack, boolean shifting, Player player, InteractionHand hand) {
|
||||
Direction facing = getBlockState().getValue(HORIZONTAL_FACING);
|
||||
|
||||
if (itemStack.is(AllBlocks.SHAFT.asItem()) && getBlockState().getValue(ENGINE_STATE) == NORMAL && !(level.getBlockEntity(getBlockPos().relative(facing)) instanceof AbstractEngineBlockEntity)) {
|
||||
@@ -143,21 +216,55 @@ public abstract class AbstractEngineBlockEntity extends KineticBlockEntity {
|
||||
return true;
|
||||
}
|
||||
if (itemStack.is(TFMGItems.SCREWDRIVER.get())) {
|
||||
for (int i = componentsInventory.components.size()-1; i >= 0; i--) {
|
||||
if (!componentsInventory.getItem(i).isEmpty()) {
|
||||
dropItem(componentsInventory.getItem(i));
|
||||
componentsInventory.setStackInSlot(i, ItemStack.EMPTY);
|
||||
playRemovalSound();
|
||||
setChanged();
|
||||
sendData();
|
||||
return true;
|
||||
}
|
||||
for (int i = componentsInventory.components.size() - 1; i >= 0; i--) {
|
||||
if (!componentsInventory.getItem(i).isEmpty()) {
|
||||
dropItem(componentsInventory.getItem(i));
|
||||
componentsInventory.setStackInSlot(i, ItemStack.EMPTY);
|
||||
playRemovalSound();
|
||||
setChanged();
|
||||
sendData();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(itemStack.is(TFMGItems.COOLING_FLUID_BOTTLE.get())){
|
||||
int toDrain = Math.min(2000-coolingFluid,itemStack.getOrCreateTag().getInt("amount"));
|
||||
itemStack.getOrCreateTag().putInt("amount",itemStack.getOrCreateTag().getInt("amount")-toDrain);
|
||||
coolingFluid+=toDrain;
|
||||
level.playSound(null, getBlockPos(), SoundEvents.BUCKET_FILL, SoundSource.BLOCKS, 1f, 1f);
|
||||
return true;
|
||||
}
|
||||
if(itemStack.is(TFMGItems.OIL_CAN.get())){
|
||||
int toDrain = Math.min(2000-oil,itemStack.getOrCreateTag().getInt("amount"));
|
||||
itemStack.getOrCreateTag().putInt("amount",itemStack.getOrCreateTag().getInt("amount")-toDrain);
|
||||
oil+=toDrain;
|
||||
level.playSound(null, getBlockPos(), SoundEvents.BUCKET_FILL, SoundSource.BLOCKS, 1f, 1f);
|
||||
return true;
|
||||
}
|
||||
if(itemStack.is(TFMGFluids.COOLING_FLUID.getBucket().get())){
|
||||
if(coolingFluid<=1000){
|
||||
coolingFluid+=1000;
|
||||
player.setItemInHand(hand, Items.BUCKET.getDefaultInstance());
|
||||
level.playSound(null, getBlockPos(), SoundEvents.BUCKET_FILL, SoundSource.BLOCKS, 1f, 1f);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(itemStack.is(TFMGFluids.LUBRICATION_OIL.getBucket().get())){
|
||||
if(oil<=1000){
|
||||
oil+=1000;
|
||||
player.setItemInHand(hand, Items.BUCKET.getDefaultInstance());
|
||||
level.playSound(null, getBlockPos(), SoundEvents.BUCKET_FILL, SoundSource.BLOCKS, 1f, 1f);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!isController())
|
||||
return false;
|
||||
if (nextComponent().test(itemStack))
|
||||
if (nextComponent().test(itemStack)) {
|
||||
if (componentsInventory.insertItem(itemStack)) {
|
||||
if (!itemStack.is(TFMGItems.SCREWDRIVER.get()))
|
||||
itemStack.shrink(1);
|
||||
@@ -166,6 +273,7 @@ public abstract class AbstractEngineBlockEntity extends KineticBlockEntity {
|
||||
sendData();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -184,9 +292,11 @@ public abstract class AbstractEngineBlockEntity extends KineticBlockEntity {
|
||||
public void playInsertionSound() {
|
||||
level.playSound(null, getBlockPos(), SoundEvents.ITEM_PICKUP, SoundSource.BLOCKS, 0.4f, 0.5f);
|
||||
}
|
||||
|
||||
public void playRemovalSound() {
|
||||
level.playSound(null, getBlockPos(), SoundEvents.ITEM_PICKUP, SoundSource.BLOCKS, 0.4f, 0.5f);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void read(CompoundTag compound, boolean clientPacket) {
|
||||
super.read(compound, clientPacket);
|
||||
@@ -195,6 +305,8 @@ public abstract class AbstractEngineBlockEntity extends KineticBlockEntity {
|
||||
componentsInventory.deserializeNBT(compound.getCompound("Components"));
|
||||
fuelTank.readFromNBT(compound.getCompound("FuelTank"));
|
||||
exhaustTank.readFromNBT(compound.getCompound("ExhaustTank"));
|
||||
oil = compound.getInt("Oil");
|
||||
coolingFluid = compound.getInt("CoolingFluid");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +318,8 @@ public abstract class AbstractEngineBlockEntity extends KineticBlockEntity {
|
||||
compound.put("Components", componentsInventory.serializeNBT());
|
||||
compound.put("FuelTank", fuelTank.writeToNBT(new CompoundTag()));
|
||||
compound.put("ExhaustTank", exhaustTank.writeToNBT(new CompoundTag()));
|
||||
|
||||
compound.putInt("Oil",oil);
|
||||
compound.putInt("CoolingFluid", coolingFluid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,11 +330,12 @@ public abstract class AbstractEngineBlockEntity extends KineticBlockEntity {
|
||||
@Override
|
||||
public boolean addToGoggleTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
|
||||
|
||||
Lang.number(controller.getX()).forGoggles(tooltip);
|
||||
Lang.number(controller.getY()).forGoggles(tooltip);
|
||||
Lang.number(controller.getZ()).forGoggles(tooltip);
|
||||
Lang.number(fuelInjectionRate).forGoggles(tooltip);
|
||||
Lang.number(rpm).style(ChatFormatting.AQUA).forGoggles(tooltip);
|
||||
|
||||
|
||||
Lang.number(engineNumber).style(ChatFormatting.DARK_GREEN).forGoggles(tooltip);
|
||||
if(isController()&&!nextComponent().isEmpty())
|
||||
if (isController() && !nextComponent().isEmpty())
|
||||
Lang.text(nextComponent().getItems()[0].getDisplayName().getString()).forGoggles(tooltip);
|
||||
|
||||
TFMGUtils.createFluidTooltip(this, tooltip);
|
||||
@@ -255,7 +369,27 @@ public abstract class AbstractEngineBlockEntity extends KineticBlockEntity {
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
public void neighbourChanged() {
|
||||
|
||||
if (!hasLevel())
|
||||
return;
|
||||
if(isController()){
|
||||
int power = level.getBestNeighborSignal(worldPosition);
|
||||
|
||||
|
||||
if (power != signal)
|
||||
signalChanged = true;
|
||||
}
|
||||
if(level.getBlockEntity(controller) instanceof AbstractEngineBlockEntity be) {
|
||||
int power = level.getBestNeighborSignal(worldPosition);
|
||||
|
||||
|
||||
if (power != be.signal)
|
||||
be.signalChanged = true;
|
||||
}
|
||||
}
|
||||
//
|
||||
public void connect() {
|
||||
Direction updateDirection = getBlockState().getValue(HORIZONTAL_FACING).getAxis() == Direction.Axis.X ? Direction.WEST : Direction.NORTH;
|
||||
if (level.getBlockEntity(getBlockPos().relative(updateDirection)) instanceof AbstractEngineBlockEntity be) {
|
||||
@@ -269,21 +403,25 @@ public abstract class AbstractEngineBlockEntity extends KineticBlockEntity {
|
||||
if (level.getBlockEntity(pos) instanceof AbstractEngineBlockEntity be) {
|
||||
if (be.getBlockState().getValue(HORIZONTAL_FACING).getAxis() != updateDirection.getAxis())
|
||||
return;
|
||||
if(be instanceof RegularEngineBlockEntity be1&&this instanceof RegularEngineBlockEntity be2 && be1.type!=be2.type)
|
||||
return;
|
||||
be.detashEngines();
|
||||
engines.add(pos.asLong());
|
||||
be.engineNumber = i;
|
||||
be.engines = new ArrayList<>();
|
||||
be.controller = getBlockPos();
|
||||
be.refreshCapability();
|
||||
level.setBlock(pos, be.getBlockState().setValue(HORIZONTAL_FACING, i > 0 ? updateDirection.getOpposite() : updateDirection), 2);
|
||||
|
||||
if(i>0)
|
||||
level.setBlock(pos, be.getBlockState().setValue(HORIZONTAL_FACING, i > 0 ? updateDirection.getOpposite() : updateDirection), 2);
|
||||
onUpdated();
|
||||
be.sendData();
|
||||
be.setChanged();
|
||||
if (be.getBlockState().getValue(ENGINE_STATE) != NORMAL) {
|
||||
if (be.getBlockState().getValue(ENGINE_STATE) != NORMAL&&i!=0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else return;
|
||||
}
|
||||
updateRotation();
|
||||
setChanged();
|
||||
sendData();
|
||||
|
||||
@@ -1,26 +1,30 @@
|
||||
package com.drmangotea.tfmg.content.engines;
|
||||
package com.drmangotea.tfmg.content.engines.base;
|
||||
|
||||
import com.drmangotea.tfmg.base.TFMGShapes;
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.content.kinetics.base.HorizontalKineticBlock;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.StringRepresentable;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
import static com.drmangotea.tfmg.content.engines.EngineBlock.EngineState.NORMAL;
|
||||
import static com.drmangotea.tfmg.content.engines.EngineBlock.EngineState.SHAFT;
|
||||
import static com.drmangotea.tfmg.content.engines.base.EngineBlock.EngineState.NORMAL;
|
||||
import static com.drmangotea.tfmg.content.engines.base.EngineBlock.EngineState.SHAFT;
|
||||
|
||||
public class EngineBlock extends HorizontalKineticBlock {
|
||||
|
||||
@@ -52,12 +56,17 @@ public class EngineBlock extends HorizontalKineticBlock {
|
||||
public InteractionResult use(BlockState blockState, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult blockHitResult) {
|
||||
|
||||
if (level.getBlockEntity(pos) instanceof AbstractEngineBlockEntity be) {
|
||||
if (be.insertItem(player.getItemInHand(hand), player.isShiftKeyDown()))
|
||||
if (be.insertItem(player.getItemInHand(hand), player.isShiftKeyDown(), player, hand))
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
return super.use(blockState, level, pos, player, hand, blockHitResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, BlockGetter p_60556_, BlockPos pos, CollisionContext p_60558_) {
|
||||
return state.getValue(ENGINE_STATE) == SHAFT ? TFMGShapes.ENGINE_FRONT.get(state.getValue(HORIZONTAL_FACING).getOpposite()) : TFMGShapes.ENGINE.get(state.getValue(HORIZONTAL_FACING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
||||
return state.getValue(ENGINE_STATE) == EngineState.SHAFT && face == state.getValue(HORIZONTAL_FACING);
|
||||
@@ -69,12 +78,14 @@ public class EngineBlock extends HorizontalKineticBlock {
|
||||
builder.add(ENGINE_STATE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Direction.Axis getRotationAxis(BlockState state) {
|
||||
return state.getValue(HORIZONTAL_FACING).getAxis();
|
||||
}
|
||||
|
||||
enum EngineState implements StringRepresentable {
|
||||
public enum EngineState implements StringRepresentable {
|
||||
|
||||
NORMAL("normal"),
|
||||
SHAFT("front"),
|
||||
@@ -1,13 +1,11 @@
|
||||
package com.drmangotea.tfmg.content.engines;
|
||||
package com.drmangotea.tfmg.content.engines.base;
|
||||
|
||||
import com.drmangotea.tfmg.base.TFMGHorizontalDirectionalBlock;
|
||||
import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry;
|
||||
import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user