This commit is contained in:
2025-03-03 22:16:00 +11:00
parent 6b4dfb054e
commit cb096ae6a8
42 changed files with 1278 additions and 2841 deletions

View File

@@ -1,28 +1,25 @@
package ru.magistu.siegemachines;
import net.minecraftforge.fml.event.lifecycle.*;
import ru.magistu.siegemachines.block.ModBlocks;
import ru.magistu.siegemachines.client.ClientProxy;
import ru.magistu.siegemachines.client.SoundTypes;
import ru.magistu.siegemachines.config.SpecsConfig;
import ru.magistu.siegemachines.item.recipes.ModRecipes;
import ru.magistu.siegemachines.entity.EntityTypes;
import ru.magistu.siegemachines.client.gui.ModMenuTypes;
import ru.magistu.siegemachines.item.ModItems;
import ru.magistu.siegemachines.network.PacketHandler;
import ru.magistu.siegemachines.proxy.IProxy;
import ru.magistu.siegemachines.server.ServerProxy;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import ru.magistu.siegemachines.block.ModBlocks;
import ru.magistu.siegemachines.client.ClientProxy;
import ru.magistu.siegemachines.client.SoundTypes;
import ru.magistu.siegemachines.client.gui.ModMenuTypes;
import ru.magistu.siegemachines.config.SpecsConfig;
import ru.magistu.siegemachines.entity.EntityTypes;
import ru.magistu.siegemachines.item.ModItems;
import ru.magistu.siegemachines.item.recipes.ModRecipes;
import ru.magistu.siegemachines.network.PacketHandler;
import ru.magistu.siegemachines.proxy.IProxy;
import ru.magistu.siegemachines.server.ServerProxy;
import java.util.UUID;
// The value here should match an entry in the META-INF/mods.toml file
@Mod(SiegeMachines.ID)
public class SiegeMachines {
public static final String ID = "siegemachines";
@@ -31,20 +28,11 @@ public class SiegeMachines {
public static final int RENDER_UPDATE_RANGE = 128;
public static final int RENDER_UPDATE_TIME = 20;
public static final int RENDER_UPDATE_RANGE_SQR = RENDER_UPDATE_RANGE * RENDER_UPDATE_RANGE;
// Directly reference a log4j logger.
private static final Logger LOGGER = LogManager.getLogger();
IEventBus eventBus;
public SiegeMachines()
{
eventBus = FMLJavaModLoadingContext.get().getModEventBus();
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
public SiegeMachines() {
IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
EntityTypes.register(eventBus);
@@ -60,32 +48,7 @@ public class SiegeMachines {
MinecraftForge.EVENT_BUS.register(this);
}
private void setup(final FMLCommonSetupEvent event)
{
}
private void doClientStuff(final FMLClientSetupEvent event)
{
private void doClientStuff(final FMLClientSetupEvent event) {
PROXY.clientSetup(event);
}
private void enqueueIMC(final InterModEnqueueEvent event)
{
}
private void processIMC(final InterModProcessEvent event)
{
}
// You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
// Event bus for receiving Registry Events)
@Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
public static class RegistryEvents
{
}
}

View File

@@ -1,7 +1,5 @@
package ru.magistu.siegemachines.block;
import ru.magistu.siegemachines.SiegeMachines;
import ru.magistu.siegemachines.item.ModItems;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.*;
import net.minecraft.world.level.Level;
@@ -12,20 +10,21 @@ import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import ru.magistu.siegemachines.SiegeMachines;
import ru.magistu.siegemachines.item.ModItems;
import javax.annotation.Nullable;
import java.util.List;
import java.util.function.Supplier;
public class ModBlocks
{
public class ModBlocks {
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, SiegeMachines.ID);
public static final RegistryObject<SiegeWorkbench> SIEGE_WORKBENCH = registerBlock("siege_workbench", () -> new SiegeWorkbench(BlockBehaviour.Properties.copy(Blocks.CRAFTING_TABLE).noOcclusion()), ModItems.GROUP_SM);
private static <T extends Block> RegistryObject<Item> registerBlockItem(String name, RegistryObject<T> block, CreativeModeTab tab, String tooltipKey) {
return ModItems.ITEMS.register(name, () -> new BlockItem(block.get(),
new Item.Properties().tab(tab)) {
new Item.Properties()) {
@Override
public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> pTooltip, TooltipFlag pFlag) {
pTooltip.add(Component.translatable(tooltipKey));
@@ -41,7 +40,7 @@ public class ModBlocks
private static <T extends Block> RegistryObject<Item> registerBlockItem(String name, RegistryObject<T> block, CreativeModeTab tab) {
return ModItems.ITEMS.register(name, () -> new BlockItem(block.get(),
new Item.Properties().tab(tab)));
new Item.Properties()));
}
public static void register(IEventBus eventBus) {

View File

@@ -17,34 +17,25 @@ import net.minecraftforge.network.NetworkHooks;
import org.jetbrains.annotations.NotNull;
import ru.magistu.siegemachines.client.gui.workbench.SiegeWorkbenchContainer;
public class SiegeWorkbench extends CraftingTableBlock
{
public class SiegeWorkbench extends CraftingTableBlock {
private static final Component CONTAINER_TITLE = Component.translatable("container.crafting");
public SiegeWorkbench(Properties p_i48422_1_)
{
public SiegeWorkbench(Properties p_i48422_1_) {
super(p_i48422_1_);
}
public @NotNull InteractionResult use(@NotNull BlockState blockstate, Level level, @NotNull BlockPos blockpos, @NotNull Player player, @NotNull InteractionHand hand, @NotNull BlockHitResult result)
{
if (level.isClientSide)
{
public @NotNull InteractionResult use(@NotNull BlockState blockstate, Level level, @NotNull BlockPos blockpos, @NotNull Player player, @NotNull InteractionHand hand, @NotNull BlockHitResult result) {
if (level.isClientSide) {
return InteractionResult.SUCCESS;
}
else
{
} else {
NetworkHooks.openScreen((ServerPlayer) player, this.getMenuProvider(blockstate, level, blockpos));
return InteractionResult.CONSUME;
}
}
@Override
public MenuProvider getMenuProvider(@NotNull BlockState blockstate, @NotNull Level level, @NotNull BlockPos blockpos)
{
public MenuProvider getMenuProvider(@NotNull BlockState blockstate, @NotNull Level level, @NotNull BlockPos blockpos) {
return new SimpleMenuProvider((p_220270_2_, p_220270_3_, p_220270_4_) ->
new SiegeWorkbenchContainer(p_220270_2_, p_220270_3_, ContainerLevelAccess.create(level, blockpos)), CONTAINER_TITLE);
}
}

View File

@@ -1,32 +1,30 @@
package ru.magistu.siegemachines.client;
import ru.magistu.siegemachines.SiegeMachines;
import ru.magistu.siegemachines.client.renderer.*;
import ru.magistu.siegemachines.entity.EntityTypes;
import net.minecraft.client.renderer.entity.ThrownItemRenderer;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import ru.magistu.siegemachines.SiegeMachines;
import ru.magistu.siegemachines.client.renderer.*;
import ru.magistu.siegemachines.entity.EntityTypes;
@Mod.EventBusSubscriber(modid = SiegeMachines.ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ClientListener
{
@SubscribeEvent
public static void registerRenderers(final EntityRenderersEvent.RegisterRenderers event)
{
public class ClientListener {
@SubscribeEvent
public static void registerRenderers(final EntityRenderersEvent.RegisterRenderers event) {
event.registerEntityRenderer(EntityTypes.MORTAR.get(), MortarGeoRenderer::new);
event.registerEntityRenderer(EntityTypes.CULVERIN.get(), CulverinGeoRenderer::new);
event.registerEntityRenderer(EntityTypes.TREBUCHET.get(), TrebuchetGeoRenderer::new);
event.registerEntityRenderer(EntityTypes.CULVERIN.get(), CulverinGeoRenderer::new);
event.registerEntityRenderer(EntityTypes.TREBUCHET.get(), TrebuchetGeoRenderer::new);
event.registerEntityRenderer(EntityTypes.CATAPULT.get(), CatapultGeoRenderer::new);
event.registerEntityRenderer(EntityTypes.BALLISTA.get(), BallistaGeoRenderer::new);
event.registerEntityRenderer(EntityTypes.BATTERING_RAM.get(), BatteringRamGeoRenderer::new);
event.registerEntityRenderer(EntityTypes.SIEGE_LADDER.get(), SiegeLadderGeoRenderer::new);
event.registerEntityRenderer(EntityTypes.BALLISTA.get(), BallistaGeoRenderer::new);
event.registerEntityRenderer(EntityTypes.BATTERING_RAM.get(), BatteringRamGeoRenderer::new);
event.registerEntityRenderer(EntityTypes.SIEGE_LADDER.get(), SiegeLadderGeoRenderer::new);
event.registerEntityRenderer(EntityTypes.CANNONBALL.get(), ThrownItemRenderer::new);
event.registerEntityRenderer(EntityTypes.GIANT_STONE.get(), ThrownItemRenderer::new);
event.registerEntityRenderer(EntityTypes.STONE.get(), ThrownItemRenderer::new);
event.registerEntityRenderer(EntityTypes.GIANT_ARROW.get(), GiantArrowRenderer::new);
event.registerEntityRenderer(EntityTypes.CANNONBALL.get(), ThrownItemRenderer::new);
event.registerEntityRenderer(EntityTypes.GIANT_STONE.get(), ThrownItemRenderer::new);
event.registerEntityRenderer(EntityTypes.STONE.get(), ThrownItemRenderer::new);
event.registerEntityRenderer(EntityTypes.GIANT_ARROW.get(), GiantArrowRenderer::new);
event.registerEntityRenderer(EntityTypes.SEAT.get(), SeatRenderer::new);
}
event.registerEntityRenderer(EntityTypes.SEAT.get(), SeatRenderer::new);
}
}

View File

@@ -1,25 +1,23 @@
package ru.magistu.siegemachines.client;
import ru.magistu.siegemachines.client.gui.ModMenuTypes;
import ru.magistu.siegemachines.client.gui.workbench.SiegeWorkbenchScreen;
import ru.magistu.siegemachines.client.gui.machine.MachineInventoryScreen;
import ru.magistu.siegemachines.proxy.IProxy;
import net.minecraft.client.gui.screens.MenuScreens;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import ru.magistu.siegemachines.client.gui.ModMenuTypes;
import ru.magistu.siegemachines.client.gui.machine.MachineInventoryScreen;
import ru.magistu.siegemachines.client.gui.workbench.SiegeWorkbenchScreen;
import ru.magistu.siegemachines.proxy.IProxy;
public class ClientProxy implements IProxy
{
public void setup(IEventBus modEventBus, IEventBus forgeEventBus)
{
public class ClientProxy implements IProxy {
public void setup(IEventBus modEventBus, IEventBus forgeEventBus) {
modEventBus.addListener(this::clientSetup);
}
public void clientSetup(FMLClientSetupEvent event)
{
public void clientSetup(FMLClientSetupEvent event) {
MenuScreens.register(ModMenuTypes.MACHINE_CONTAINER.get(), MachineInventoryScreen::new);
MenuScreens.register(ModMenuTypes.SIEGE_WORKBENCH_CONTAINER.get(), SiegeWorkbenchScreen::new);
}
public void onPreInit() {}
public void onPreInit() {
}
}

View File

@@ -1,17 +1,15 @@
package ru.magistu.siegemachines.client;
import ru.magistu.siegemachines.SiegeMachines;
import net.minecraft.client.KeyMapping;
import ru.magistu.siegemachines.SiegeMachines;
import ru.magistu.siegemachines.entity.machine.MachineType;
public class KeyBindings
{
public class KeyBindings {
public static KeyMapping MACHINE_USE = new KeyMapping(SiegeMachines.ID + ".machine_use", 70, SiegeMachines.ID + ".category");
public static KeyMapping LADDER_CLIMB = new KeyMapping(SiegeMachines.ID + ".ladder_climb", 32, SiegeMachines.ID + ".category");
public static KeyMapping MACHINE_INVENTORY = new KeyMapping(SiegeMachines.ID + ".machine_inventory", 73, SiegeMachines.ID + ".category");
public static KeyMapping getUseKey(MachineType type)
{
public static KeyMapping getUseKey(MachineType type) {
if (type == MachineType.SIEGE_LADDER)
return LADDER_CLIMB;
return MACHINE_USE;

View File

@@ -1,6 +1,5 @@
package ru.magistu.siegemachines.client.gui.machine;
import ru.magistu.siegemachines.entity.machine.Machine;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Inventory;
@@ -8,129 +7,96 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import org.jetbrains.annotations.NotNull;
import ru.magistu.siegemachines.client.gui.ModMenuTypes;
import ru.magistu.siegemachines.entity.machine.Machine;
import java.util.Objects;
public class MachineContainer extends AbstractContainerMenu
{
private Player player;
private Machine machine;
int x, y, z;
private IItemHandler internal;
private boolean bound = false;
public class MachineContainer extends AbstractContainerMenu {
private Machine machine;
public MachineContainer(final int id, final Inventory inv, final Machine machine) {
super(ModMenuTypes.MACHINE_CONTAINER.get(), id);
if (machine == null) {
return;
}
this.machine = machine;
public MachineContainer(final int id, final Inventory inv, final Machine machine)
{
super(ModMenuTypes.MACHINE_CONTAINER.get(), id);
if (machine == null)
{
return;
}
this.machine = machine;
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 9; col++) {
this.addSlot(new Slot(inv, col + row * 9 + 9, 8 + col * 18, 166 - (4 - row) * 18 - 10));
}
}
for (int row = 0; row < 3; row++)
{
for (int col = 0; col < 9; col++)
{
this.addSlot(new Slot(inv, col + row * 9 + 9, 8 + col * 18, 166 - (4 - row) * 18 - 10));
}
}
for (int col = 0; col < 9; col++) {
this.addSlot(new Slot(inv, col, 8 + col * 18, 142));
}
for (int col = 0; col < 9; col++)
{
this.addSlot(new Slot(inv, col, 8 + col * 18, 142));
}
for (int row = 0; row < 1; row++) {
for (int col = 0; col < 9; col++) {
this.addSlot(new Slot(machine.inventory, col + row * 9, 8 + col * 18, 18 + row * 18));
}
}
}
for (int row = 0; row < 1; row++)
{
for (int col = 0; col < 9; col++)
{
this.addSlot(new Slot(machine.inventory, col + row * 9, 8 + col * 18, 18 + row * 18));
}
}
}
public MachineContainer(final int id, final Inventory inv, final FriendlyByteBuf data) {
this(id, inv, getMachine(inv));
}
public MachineContainer(final int id, final Inventory inv, final FriendlyByteBuf data)
{
this(id, inv, getMachine(inv));
}
private static Machine getMachine(final Inventory inv) {
Objects.requireNonNull(inv, "Player Inventory Cannot Be Null.");
Player player = inv.player;
Entity entity;
if (player.isPassenger()) {
entity = player.getVehicle();
if (entity instanceof Machine) {
return (Machine) player.getVehicle();
}
}
private static Machine getMachine(final Inventory inv)
{
Objects.requireNonNull(inv, "Player Inventory Cannot Be Null.");
Player player = inv.player;
Entity entity;
if (player.isPassenger())
{
entity = player.getVehicle();
if (entity instanceof Machine)
{
return (Machine) player.getVehicle();
}
}
throw new IllegalStateException("Entity Is Not Correct.");
}
throw new IllegalStateException("Entity Is Not Correct.");
}
@Override
public boolean stillValid(Player player) {
return machine.inventory.stillValid(player);
}
@Override
public boolean stillValid(Player player)
{
return machine.inventory.stillValid(player);
}
@Override
public @NotNull ItemStack quickMoveStack(@NotNull Player player, int index)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.slots.get(index);
if (slot != null && slot.hasItem())
{
ItemStack itemstack1 = slot.getItem();
itemstack = itemstack1.copy();
if (index < 9)
{
if (!this.moveItemStackTo(itemstack1, 9, this.slots.size(), true))
{
return ItemStack.EMPTY;
}
slot.onQuickCraft(itemstack1, itemstack);
}
else if (!this.moveItemStackTo(itemstack1, 0, 9, false))
{
if (index < 9 + 27)
{
if (!this.moveItemStackTo(itemstack1, 9 + 27, this.slots.size(), true))
{
return ItemStack.EMPTY;
}
}
else
{
if (!this.moveItemStackTo(itemstack1, 9, 9 + 27, false))
{
return ItemStack.EMPTY;
}
}
return ItemStack.EMPTY;
}
if (itemstack1.getCount() == 0)
{
slot.set(ItemStack.EMPTY);
}
else
{
slot.setChanged();
}
if (itemstack1.getCount() == itemstack.getCount())
{
return ItemStack.EMPTY;
}
slot.onTake(player, itemstack1);
}
return itemstack;
}
@Override
public @NotNull ItemStack quickMoveStack(@NotNull Player player, int index) {
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.slots.get(index);
if (slot != null && slot.hasItem()) {
ItemStack itemstack1 = slot.getItem();
itemstack = itemstack1.copy();
if (index < 9) {
if (!this.moveItemStackTo(itemstack1, 9, this.slots.size(), true)) {
return ItemStack.EMPTY;
}
slot.onQuickCraft(itemstack1, itemstack);
} else if (!this.moveItemStackTo(itemstack1, 0, 9, false)) {
if (index < 9 + 27) {
if (!this.moveItemStackTo(itemstack1, 9 + 27, this.slots.size(), true)) {
return ItemStack.EMPTY;
}
} else {
if (!this.moveItemStackTo(itemstack1, 9, 9 + 27, false)) {
return ItemStack.EMPTY;
}
}
return ItemStack.EMPTY;
}
if (itemstack1.getCount() == 0) {
slot.set(ItemStack.EMPTY);
} else {
slot.setChanged();
}
if (itemstack1.getCount() == itemstack.getCount()) {
return ItemStack.EMPTY;
}
slot.onTake(player, itemstack1);
}
return itemstack;
}
}

View File

@@ -2,14 +2,12 @@ package ru.magistu.siegemachines.config;
import net.minecraftforge.common.ForgeConfigSpec;
public class MissileSpecs
{
public class MissileSpecs {
public final ForgeConfigSpec.ConfigValue<Float> mass;
public final ForgeConfigSpec.ConfigValue<Float> explosionpower;
public final ForgeConfigSpec.ConfigValue<Boolean> destroysground;
public MissileSpecs(ForgeConfigSpec.Builder builder, String name, float mass, float explosionpower, boolean destroysground)
{
public MissileSpecs(ForgeConfigSpec.Builder builder, String name, float mass, float explosionpower, boolean destroysground) {
builder.push(name);
this.mass = builder.define("mass", mass);

View File

@@ -2,8 +2,7 @@ package ru.magistu.siegemachines.config;
import net.minecraftforge.common.ForgeConfigSpec;
public final class SiegeMachineSpecs
{
public final class SiegeMachineSpecs {
private final String name;
public final ForgeConfigSpec.ConfigValue<Integer> durability;
@@ -12,8 +11,7 @@ public final class SiegeMachineSpecs
public final ForgeConfigSpec.ConfigValue<Float> inaccuracy;
public final ForgeConfigSpec.ConfigValue<Float> damagemultiplier;
public SiegeMachineSpecs(ForgeConfigSpec.Builder builder, String name, int durability, int delaytime, float projectilespeed, float inaccuracy, float damagemultiplier)
{
public SiegeMachineSpecs(ForgeConfigSpec.Builder builder, String name, int durability, int delaytime, float projectilespeed, float inaccuracy, float damagemultiplier) {
this.name = name;
builder.push(name);

View File

@@ -4,8 +4,7 @@ import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.config.ModConfig;
public final class SpecsConfig
{
public final class SpecsConfig {
public static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
public static final ForgeConfigSpec SPEC;
@@ -21,10 +20,9 @@ public final class SpecsConfig
public static final MissileSpecs STONE;
public static final MissileSpecs GIANT_STONE;
static
{
static {
BUILDER.push("siege_machines");
MORTAR = new SiegeMachineSpecs(BUILDER, "mortar", 80, 200, 2.5f, 0.2f, 1.5f);
CULVERIN = new SiegeMachineSpecs(BUILDER, "culverin", 150, 260, 3.5f, 0.03f, 3.0f);
TREBUCHET = new SiegeMachineSpecs(BUILDER, "trebuchet", 350, 400, 2.8f, 0.2f, 2.0f);
@@ -42,12 +40,11 @@ public final class SpecsConfig
GIANT_STONE = new MissileSpecs(BUILDER, "giant_stone", 70.0f, 5.0f, false);
BUILDER.pop();
SPEC = BUILDER.build();
}
public static void register()
{
public static void register() {
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, SPEC, "siege-machines-specs.toml");
}
}

View File

@@ -1,14 +1,9 @@
package ru.magistu.siegemachines.entity;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.mojang.datafixers.util.Pair;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import java.util.*;
import javax.annotation.Nullable;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
@@ -21,7 +16,6 @@ import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.item.PrimedTnt;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.ProtectionEnchantment;
import net.minecraft.world.level.*;
@@ -31,299 +25,263 @@ import net.minecraft.world.level.block.FireBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
public class Breakdown
{
import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
public class Breakdown {
private static final ExplosionDamageCalculator EXPLOSION_DAMAGE_CALCULATOR = new ExplosionDamageCalculator();
private final boolean fire;
private final Explosion.BlockInteraction blockInteraction;
private final RandomSource random = RandomSource.create();
private final Level level;
private final double x;
private final double y;
private final double z;
@Nullable
private final Entity source;
private final float radius;
private final DamageSource damageSource;
private final ExplosionDamageCalculator damageCalculator;
private final ObjectArrayList<BlockPos> toBlow = new ObjectArrayList<>();
private final Map<Player, Vec3> hitPlayers = Maps.newHashMap();
private final Vec3 position;
private final Explosion explosion;
private final Entity machine;
private final float power;
private final boolean fire;
private final Explosion.BlockInteraction blockInteraction;
private final RandomSource random = RandomSource.create();
private final Level level;
private final double x;
private final double y;
private final double z;
@Nullable
private final Entity source;
private final float radius;
private final DamageSource damageSource;
private final ExplosionDamageCalculator damageCalculator;
private final ObjectArrayList<BlockPos> toBlow = new ObjectArrayList<>();
private final Map<Player, Vec3> hitPlayers = Maps.newHashMap();
private final Vec3 position;
private final Explosion explosion;
private final Entity machine;
private final float power;
public Breakdown(Level p_i50007_1_, @Nullable Entity machine, @Nullable Entity p_i50007_2_, double p_i50007_3_, double p_i50007_5_, double p_i50007_7_, float p_i50007_9_, boolean p_i50007_10_, float power, Explosion.BlockInteraction p_i50007_11_) {
this(p_i50007_1_, p_i50007_2_, machine, (DamageSource)null, (ExplosionDamageCalculator)null, p_i50007_3_, p_i50007_5_, p_i50007_7_, p_i50007_9_, p_i50007_10_, power, p_i50007_11_);
}
public Breakdown(Level p_i50007_1_, @Nullable Entity machine, @Nullable Entity p_i50007_2_, double p_i50007_3_, double p_i50007_5_, double p_i50007_7_, float p_i50007_9_, boolean p_i50007_10_, float power, Explosion.BlockInteraction p_i50007_11_) {
this(p_i50007_1_, p_i50007_2_, machine, (DamageSource) null, (ExplosionDamageCalculator) null, p_i50007_3_, p_i50007_5_, p_i50007_7_, p_i50007_9_, p_i50007_10_, power, p_i50007_11_);
}
public Breakdown(Level p_i231610_1_, @Nullable Entity machine, @Nullable Entity p_i231610_2_, @Nullable DamageSource p_i231610_3_, @Nullable ExplosionDamageCalculator p_i231610_4_, double p_i231610_5_, double p_i231610_7_, double p_i231610_9_, float p_i231610_11_, boolean p_i231610_12_, float power, Explosion.BlockInteraction p_i231610_13_) {
this.explosion = new Explosion(p_i231610_1_, p_i231610_2_, p_i231610_3_, p_i231610_4_, p_i231610_5_, p_i231610_7_, p_i231610_9_, p_i231610_11_, p_i231610_12_, p_i231610_13_);
this.level = p_i231610_1_;
this.machine = machine;
this.source = p_i231610_2_;
this.radius = p_i231610_11_;
this.x = p_i231610_5_;
this.y = p_i231610_7_;
this.z = p_i231610_9_;
this.fire = p_i231610_12_;
this.power = power;
this.blockInteraction = p_i231610_13_;
this.damageSource = p_i231610_3_ == null && p_i231610_2_ instanceof LivingEntity ? DamageSource.explosion((LivingEntity) p_i231610_2_) : p_i231610_3_;
this.damageCalculator = p_i231610_4_ == null ? this.makeDamageCalculator(p_i231610_2_) : p_i231610_4_;
this.position = new Vec3(this.x, this.y, this.z);
}
public Breakdown(Level p_i231610_1_, @Nullable Entity machine, @Nullable Entity p_i231610_2_, @Nullable DamageSource p_i231610_3_, @Nullable ExplosionDamageCalculator p_i231610_4_, double p_i231610_5_, double p_i231610_7_, double p_i231610_9_, float p_i231610_11_, boolean p_i231610_12_, float power, Explosion.BlockInteraction p_i231610_13_) {
this.explosion = new Explosion(p_i231610_1_, p_i231610_2_, p_i231610_3_, p_i231610_4_, p_i231610_5_, p_i231610_7_, p_i231610_9_, p_i231610_11_, p_i231610_12_, p_i231610_13_);
this.level = p_i231610_1_;
this.machine = machine;
this.source = p_i231610_2_;
this.radius = p_i231610_11_;
this.x = p_i231610_5_;
this.y = p_i231610_7_;
this.z = p_i231610_9_;
this.fire = p_i231610_12_;
this.power = power;
this.blockInteraction = p_i231610_13_;
// this.damageSource = p_i231610_3_ == null && p_i231610_2_ instanceof LivingEntity ? DamageSource.explosion((LivingEntity) p_i231610_2_) : p_i231610_3_;
this.damageSource = p_i231610_3_ == null && p_i231610_2_ instanceof LivingEntity ? level.damageSources().explosion(p_i231610_2_, p_i231610_2_) : p_i231610_3_; //TODO Возможно неправильно
this.damageCalculator = p_i231610_4_ == null ? this.makeDamageCalculator(p_i231610_2_) : p_i231610_4_;
this.position = new Vec3(this.x, this.y, this.z);
}
private ExplosionDamageCalculator makeDamageCalculator(@Nullable Entity p_234894_1_) {
return (p_234894_1_ == null ? EXPLOSION_DAMAGE_CALCULATOR : new EntityBasedExplosionDamageCalculator(p_234894_1_));
}
private ExplosionDamageCalculator makeDamageCalculator(@Nullable Entity p_234894_1_) {
return (p_234894_1_ == null ? EXPLOSION_DAMAGE_CALCULATOR : new EntityBasedExplosionDamageCalculator(p_234894_1_));
}
public static float getSeenPercent(Vec3 p_222259_0_, Entity p_222259_1_) {
AABB axisalignedbb = p_222259_1_.getBoundingBox();
double d0 = 1.0D / ((axisalignedbb.maxX - axisalignedbb.minX) * 2.0D + 1.0D);
double d1 = 1.0D / ((axisalignedbb.maxY - axisalignedbb.minY) * 2.0D + 1.0D);
double d2 = 1.0D / ((axisalignedbb.maxZ - axisalignedbb.minZ) * 2.0D + 1.0D);
double d3 = (1.0D - Math.floor(1.0D / d0) * d0) / 2.0D;
double d4 = (1.0D - Math.floor(1.0D / d2) * d2) / 2.0D;
if (!(d0 < 0.0D) && !(d1 < 0.0D) && !(d2 < 0.0D)) {
int i = 0;
int j = 0;
public static float getSeenPercent(Vec3 p_222259_0_, Entity p_222259_1_) {
AABB axisalignedbb = p_222259_1_.getBoundingBox();
double d0 = 1.0D / ((axisalignedbb.maxX - axisalignedbb.minX) * 2.0D + 1.0D);
double d1 = 1.0D / ((axisalignedbb.maxY - axisalignedbb.minY) * 2.0D + 1.0D);
double d2 = 1.0D / ((axisalignedbb.maxZ - axisalignedbb.minZ) * 2.0D + 1.0D);
double d3 = (1.0D - Math.floor(1.0D / d0) * d0) / 2.0D;
double d4 = (1.0D - Math.floor(1.0D / d2) * d2) / 2.0D;
if (!(d0 < 0.0D) && !(d1 < 0.0D) && !(d2 < 0.0D)) {
int i = 0;
int j = 0;
for(float f = 0.0F; f <= 1.0F; f = (float)((double)f + d0)) {
for(float f1 = 0.0F; f1 <= 1.0F; f1 = (float)((double)f1 + d1)) {
for(float f2 = 0.0F; f2 <= 1.0F; f2 = (float)((double)f2 + d2)) {
double d5 = Mth.lerp((double)f, axisalignedbb.minX, axisalignedbb.maxX);
double d6 = Mth.lerp((double)f1, axisalignedbb.minY, axisalignedbb.maxY);
double d7 = Mth.lerp((double)f2, axisalignedbb.minZ, axisalignedbb.maxZ);
Vec3 vector3d = new Vec3(d5 + d3, d6, d7 + d4);
if (p_222259_1_.level.clip(new ClipContext(vector3d, p_222259_0_, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, p_222259_1_)).getType() == HitResult.Type.MISS) {
++i;
}
for (float f = 0.0F; f <= 1.0F; f = (float) ((double) f + d0)) {
for (float f1 = 0.0F; f1 <= 1.0F; f1 = (float) ((double) f1 + d1)) {
for (float f2 = 0.0F; f2 <= 1.0F; f2 = (float) ((double) f2 + d2)) {
double d5 = Mth.lerp((double) f, axisalignedbb.minX, axisalignedbb.maxX);
double d6 = Mth.lerp((double) f1, axisalignedbb.minY, axisalignedbb.maxY);
double d7 = Mth.lerp((double) f2, axisalignedbb.minZ, axisalignedbb.maxZ);
Vec3 vector3d = new Vec3(d5 + d3, d6, d7 + d4);
if (p_222259_1_.level().clip(new ClipContext(vector3d, p_222259_0_, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, p_222259_1_)).getType() == HitResult.Type.MISS) {
++i;
}
++j;
}
++j;
}
}
}
}
return (float)i / (float)j;
} else {
return 0.0F;
}
}
return (float) i / (float) j;
} else {
return 0.0F;
}
}
public void explode()
{
Set<BlockPos> set = Sets.newHashSet();
int i = 16;
public void explode() {
Set<BlockPos> set = Sets.newHashSet();
int i = 16;
for(int j = 0; j < 16; ++j) {
for(int k = 0; k < 16; ++k) {
for(int l = 0; l < 16; ++l) {
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
double d0 = (double)((float)j / 15.0F * 2.0F - 1.0F);
double d1 = (double)((float)k / 15.0F * 2.0F - 1.0F);
double d2 = (double)((float)l / 15.0F * 2.0F - 1.0F);
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
d0 = d0 / d3;
d1 = d1 / d3;
d2 = d2 / d3;
float f = this.power * this.radius * (0.7F + this.level.random.nextFloat() * 0.6F);
double d4 = this.x;
double d6 = this.y;
double d8 = this.z;
for (int j = 0; j < 16; ++j) {
for (int k = 0; k < 16; ++k) {
for (int l = 0; l < 16; ++l) {
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
double d0 = (double) ((float) j / 15.0F * 2.0F - 1.0F);
double d1 = (double) ((float) k / 15.0F * 2.0F - 1.0F);
double d2 = (double) ((float) l / 15.0F * 2.0F - 1.0F);
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
d0 = d0 / d3;
d1 = d1 / d3;
d2 = d2 / d3;
float f = this.power * this.radius * (0.7F + this.level.random.nextFloat() * 0.6F);
double d4 = this.x;
double d6 = this.y;
double d8 = this.z;
for(float f1 = 0.3F; f > 0.0F; f -= this.power * 0.5F) {
BlockPos blockpos = new BlockPos(d4, d6, d8);
BlockState blockstate = this.level.getBlockState(blockpos);
FluidState fluidstate = this.level.getFluidState(blockpos);
Optional<Float> optional = this.damageCalculator.getBlockExplosionResistance(this.explosion, this.level, blockpos, blockstate, fluidstate);
if (optional.isPresent()) {
f -= (optional.get() + 0.3F) * 0.3F;
}
for (float f1 = 0.3F; f > 0.0F; f -= this.power * 0.5F) {
BlockPos blockpos = new BlockPos((int) d4, (int) d6, (int) d8); //TODO ранее был double
BlockState blockstate = this.level.getBlockState(blockpos);
FluidState fluidstate = this.level.getFluidState(blockpos);
Optional<Float> optional = this.damageCalculator.getBlockExplosionResistance(this.explosion, this.level, blockpos, blockstate, fluidstate);
if (optional.isPresent()) {
f -= (optional.get() + 0.3F) * 0.3F;
}
if (f > 0.0F && this.damageCalculator.shouldBlockExplode(this.explosion, this.level, blockpos, blockstate, f)) {
set.add(blockpos);
}
if (f > 0.0F && this.damageCalculator.shouldBlockExplode(this.explosion, this.level, blockpos, blockstate, f)) {
set.add(blockpos);
}
d4 += d0 * (double)0.3F;
d6 += d1 * (double)0.3F;
d8 += d2 * (double)0.3F;
}
}
d4 += d0 * (double) 0.3F;
d6 += d1 * (double) 0.3F;
d8 += d2 * (double) 0.3F;
}
}
}
}
}
}
}
this.toBlow.addAll(set);
float f2 = 1.5f * this.radius;
int k1 = Mth.floor(this.x - (double)f2 - 1.0D);
int l1 = Mth.floor(this.x + (double)f2 + 1.0D);
int i2 = Mth.floor(this.y - (double)f2 - 1.0D);
int i1 = Mth.floor(this.y + (double)f2 + 1.0D);
int j2 = Mth.floor(this.z - (double)f2 - 1.0D);
int j1 = Mth.floor(this.z + (double)f2 + 1.0D);
List<Entity> list = this.level.getEntities(this.source, new AABB((double)k1, (double)i2, (double)j2, (double)l1, (double)i1, (double)j1));
Vec3 vector3d = new Vec3(this.x, this.y, this.z);
this.toBlow.addAll(set);
float f2 = 1.5f * this.radius;
int k1 = Mth.floor(this.x - (double) f2 - 1.0D);
int l1 = Mth.floor(this.x + (double) f2 + 1.0D);
int i2 = Mth.floor(this.y - (double) f2 - 1.0D);
int i1 = Mth.floor(this.y + (double) f2 + 1.0D);
int j2 = Mth.floor(this.z - (double) f2 - 1.0D);
int j1 = Mth.floor(this.z + (double) f2 + 1.0D);
List<Entity> list = this.level.getEntities(this.source, new AABB((double) k1, (double) i2, (double) j2, (double) l1, (double) i1, (double) j1));
Vec3 vector3d = new Vec3(this.x, this.y, this.z);
for(int k2 = 0; k2 < list.size(); ++k2) {
Entity entity = list.get(k2);
if (!entity.ignoreExplosion() && !entity.equals(this.machine) && !entity.equals(this.source)) {
double d12 = (Mth.sqrt((float) entity.distanceToSqr(vector3d)) / f2);
if (d12 <= 1.0D) {
double d5 = entity.getX() - this.x;
double d7 = (entity instanceof PrimedTnt ? entity.getY() : entity.getEyeY()) - this.y;
double d9 = entity.getZ() - this.z;
double d13 = Mth.sqrt((float) (d5 * d5 + d7 * d7 + d9 * d9));
if (d13 != 0.0D) {
d5 = d5 / d13;
d7 = d7 / d13;
d9 = d9 / d13;
double d14 = getSeenPercent(vector3d, entity);
double d10 = (1.0D - d12) * d14;
if (!(entity instanceof ItemEntity)) {
entity.hurt(this.getDamageSource(), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f2 + 1.0D)));
}
double d11 = d10;
if (entity instanceof LivingEntity) {
d11 = ProtectionEnchantment.getExplosionKnockbackAfterDampener((LivingEntity)entity, d10);
}
for (int k2 = 0; k2 < list.size(); ++k2) {
Entity entity = list.get(k2);
if (!entity.ignoreExplosion() && !entity.equals(this.machine) && !entity.equals(this.source)) {
double d12 = (Mth.sqrt((float) entity.distanceToSqr(vector3d)) / f2);
if (d12 <= 1.0D) {
double d5 = entity.getX() - this.x;
double d7 = (entity instanceof PrimedTnt ? entity.getY() : entity.getEyeY()) - this.y;
double d9 = entity.getZ() - this.z;
double d13 = Mth.sqrt((float) (d5 * d5 + d7 * d7 + d9 * d9));
if (d13 != 0.0D) {
d5 = d5 / d13;
d7 = d7 / d13;
d9 = d9 / d13;
double d14 = getSeenPercent(vector3d, entity);
double d10 = (1.0D - d12) * d14;
if (!(entity instanceof ItemEntity)) {
entity.hurt(this.getDamageSource(), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f2 + 1.0D)));
}
double d11 = d10;
if (entity instanceof LivingEntity) {
d11 = ProtectionEnchantment.getExplosionKnockbackAfterDampener((LivingEntity) entity, d10);
}
entity.setDeltaMovement(entity.getDeltaMovement().add(d5 * d11, d7 * d11, d9 * d11));
if (entity instanceof Player) {
Player playerentity = (Player)entity;
if (!playerentity.isSpectator() && (!playerentity.isCreative() || !playerentity.getAbilities().flying)) {
this.hitPlayers.put(playerentity, new Vec3(d5 * d10, d7 * d10, d9 * d10));
}
}
}
entity.setDeltaMovement(entity.getDeltaMovement().add(d5 * d11, d7 * d11, d9 * d11));
if (entity instanceof Player) {
Player playerentity = (Player) entity;
if (!playerentity.isSpectator() && (!playerentity.isCreative() || !playerentity.getAbilities().flying)) {
this.hitPlayers.put(playerentity, new Vec3(d5 * d10, d7 * d10, d9 * d10));
}
}
}
}
}
}
}
}
}
}
public void finalizeExplosion(boolean p_77279_1_) {
if (this.level.isClientSide) {
//this.level.playLocalSound(this.x, this.y, this.z, SoundEvents.GENERIC_EXPLODE, SoundCategory.BLOCKS, 4.0F, (1.0F + (this.level.random.nextFloat() - this.level.random.nextFloat()) * 0.2F) * 0.7F, false);
}
boolean flag = this.blockInteraction != Explosion.BlockInteraction.NONE;
if (p_77279_1_) {
if (!(this.radius < 2.0F) && flag) {
this.level.addParticle(ParticleTypes.EXPLOSION_EMITTER, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
} else {
this.level.addParticle(ParticleTypes.EXPLOSION, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
}
}
if (flag) {
ObjectArrayList<Pair<ItemStack, BlockPos>> objectarraylist = new ObjectArrayList<>();
Util.shuffle(this.toBlow, random);
for(BlockPos blockpos : this.toBlow) {
BlockState blockstate = this.level.getBlockState(blockpos);
Block block = blockstate.getBlock();
if (!blockstate.isAir()) {
BlockPos blockpos1 = blockpos.immutable();
this.level.getProfiler().push("explosion_blocks");
if (this.level instanceof ServerLevel) {
BlockEntity tileentity = blockstate.hasBlockEntity() ? this.level.getBlockEntity(blockpos) : null;
LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerLevel)this.level)).withRandom(this.level.random).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(blockpos)).withParameter(LootContextParams.TOOL, ItemStack.EMPTY).withOptionalParameter(LootContextParams.BLOCK_ENTITY, tileentity).withOptionalParameter(LootContextParams.THIS_ENTITY, this.source);
if (this.blockInteraction == Explosion.BlockInteraction.DESTROY) {
lootcontext$builder.withParameter(LootContextParams.EXPLOSION_RADIUS, this.radius);
}
blockstate.getDrops(lootcontext$builder).forEach((p_229977_2_) -> {
addBlockDrops(objectarraylist, p_229977_2_, blockpos1);
});
}
this.level.setBlock(blockpos, Blocks.AIR.defaultBlockState(), 3);
this.level.getProfiler().pop();
public void finalizeExplosion(boolean p_77279_1_) {
boolean flag = this.blockInteraction != Explosion.BlockInteraction.KEEP; //TODO Стоял NONE, поставил KEEP, возможно неверно
if (p_77279_1_) {
if (!(this.radius < 2.0F) && flag) {
this.level.addParticle(ParticleTypes.EXPLOSION_EMITTER, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
} else {
this.level.addParticle(ParticleTypes.EXPLOSION, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
}
}
}
for(Pair<ItemStack, BlockPos> pair : objectarraylist) {
Block.popResource(this.level, pair.getSecond(), pair.getFirst());
}
}
if (flag) {
ObjectArrayList<Pair<ItemStack, BlockPos>> objectarraylist = new ObjectArrayList<>();
Util.shuffle(this.toBlow, random);
if (this.fire) {
for(BlockPos blockpos2 : this.toBlow) {
if (this.random.nextInt(3) == 0 && this.level.getBlockState(blockpos2).isAir() && this.level.getBlockState(blockpos2.below()).isSolidRender(this.level, blockpos2.below())) {
this.level.setBlockAndUpdate(blockpos2, FireBlock.getState(this.level, blockpos2));
for (BlockPos blockpos : this.toBlow) {
BlockState blockstate = this.level.getBlockState(blockpos);
Block block = blockstate.getBlock();
if (!blockstate.isAir()) {
BlockPos blockpos1 = blockpos.immutable();
this.level.getProfiler().push("explosion_blocks");
if (this.level instanceof ServerLevel) {
BlockEntity tileentity = blockstate.hasBlockEntity() ? this.level.getBlockEntity(blockpos) : null;
LootParams.Builder lootcontext$builder = (new LootParams.Builder((ServerLevel) this.level)).withLuck(this.level.random.nextFloat()).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(blockpos)).withParameter(LootContextParams.TOOL, ItemStack.EMPTY).withOptionalParameter(LootContextParams.BLOCK_ENTITY, tileentity).withOptionalParameter(LootContextParams.THIS_ENTITY, this.source);
if (this.blockInteraction == Explosion.BlockInteraction.DESTROY) {
lootcontext$builder.withParameter(LootContextParams.EXPLOSION_RADIUS, this.radius);
}
blockstate.getDrops(lootcontext$builder).forEach((p_229977_2_) -> {
addBlockDrops(objectarraylist, p_229977_2_, blockpos1);
});
}
this.level.setBlock(blockpos, Blocks.AIR.defaultBlockState(), 3);
this.level.getProfiler().pop();
}
}
}
}
}
private static void addBlockDrops(ObjectArrayList<Pair<ItemStack, BlockPos>> p_46068_, ItemStack p_46069_, BlockPos p_46070_) {
int i = p_46068_.size();
for(int j = 0; j < i; ++j) {
Pair<ItemStack, BlockPos> pair = p_46068_.get(j);
ItemStack itemstack = pair.getFirst();
if (ItemEntity.areMergable(itemstack, p_46069_)) {
ItemStack itemstack1 = ItemEntity.merge(itemstack, p_46069_, 16);
p_46068_.set(j, Pair.of(itemstack1, pair.getSecond()));
if (p_46069_.isEmpty()) {
return;
for (Pair<ItemStack, BlockPos> pair : objectarraylist) {
Block.popResource(this.level, pair.getSecond(), pair.getFirst());
}
}
}
}
p_46068_.add(Pair.of(p_46069_, p_46070_));
}
public DamageSource getDamageSource() {
return this.damageSource;
}
public Map<Player, Vec3> getHitPlayers() {
return this.hitPlayers;
}
@Nullable
public LivingEntity getSourceMob() {
if (this.source == null) {
return null;
} else if (this.source instanceof PrimedTnt) {
return ((PrimedTnt)this.source).getOwner();
} else if (this.source instanceof LivingEntity) {
return (LivingEntity)this.source;
} else {
if (this.source instanceof Projectile) {
Entity entity = ((Projectile)this.source).getOwner();
if (entity instanceof LivingEntity) {
return (LivingEntity)entity;
if (this.fire) {
for (BlockPos blockpos2 : this.toBlow) {
if (this.random.nextInt(3) == 0 && this.level.getBlockState(blockpos2).isAir() && this.level.getBlockState(blockpos2.below()).isSolidRender(this.level, blockpos2.below())) {
this.level.setBlockAndUpdate(blockpos2, FireBlock.getState(this.level, blockpos2));
}
}
}
}
return null;
}
}
}
public void clearToBlow() {
this.toBlow.clear();
}
private static void addBlockDrops(ObjectArrayList<Pair<ItemStack, BlockPos>> p_46068_, ItemStack p_46069_, BlockPos p_46070_) {
int i = p_46068_.size();
public List<BlockPos> getToBlow() {
return this.toBlow;
}
for (int j = 0; j < i; ++j) {
Pair<ItemStack, BlockPos> pair = p_46068_.get(j);
ItemStack itemstack = pair.getFirst();
if (ItemEntity.areMergable(itemstack, p_46069_)) {
ItemStack itemstack1 = ItemEntity.merge(itemstack, p_46069_, 16);
p_46068_.set(j, Pair.of(itemstack1, pair.getSecond()));
if (p_46069_.isEmpty()) {
return;
}
}
}
public Vec3 getPosition() {
return this.position;
}
p_46068_.add(Pair.of(p_46069_, p_46070_));
}
@Nullable
public Entity getExploder() {
return this.source;
}
public DamageSource getDamageSource() {
return this.damageSource;
}
public Vec3 getPosition() {
return this.position;
}
}

View File

@@ -1,11 +1,5 @@
package ru.magistu.siegemachines.entity;
import ru.magistu.siegemachines.SiegeMachines;
import ru.magistu.siegemachines.entity.machine.*;
import ru.magistu.siegemachines.entity.projectile.Cannonball;
import ru.magistu.siegemachines.entity.projectile.GiantArrow;
import ru.magistu.siegemachines.entity.projectile.GiantStone;
import ru.magistu.siegemachines.entity.projectile.Stone;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
@@ -14,9 +8,14 @@ import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import ru.magistu.siegemachines.SiegeMachines;
import ru.magistu.siegemachines.entity.machine.*;
import ru.magistu.siegemachines.entity.projectile.Cannonball;
import ru.magistu.siegemachines.entity.projectile.GiantArrow;
import ru.magistu.siegemachines.entity.projectile.GiantStone;
import ru.magistu.siegemachines.entity.projectile.Stone;
public class EntityTypes
{
public class EntityTypes {
public static final DeferredRegister<EntityType<?>> DEFERRED_REGISTER = DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, SiegeMachines.ID);
public static final RegistryObject<EntityType<Cannonball>> CANNONBALL = addRegistry("cannonball", Cannonball::new, 0.5f, 0.5f);
@@ -31,21 +30,18 @@ public class EntityTypes
public static final RegistryObject<EntityType<Ballista>> BALLISTA = addRegistry("ballista", Ballista::new, 1.5f, 1.5f, 10);
public static final RegistryObject<EntityType<BatteringRam>> BATTERING_RAM = addRegistry("battering_ram", BatteringRam::new, 4.0f, 3.0f, 10);
public static final RegistryObject<EntityType<SiegeLadder>> SIEGE_LADDER = addRegistry("siege_ladder", SiegeLadder::new, 3.0f, 3.0f, 10);
public static final RegistryObject<EntityType<Seat>> SEAT = addRegistry("seat", Seat::new, 0.0f, 0.0f);
public static <T extends Entity> RegistryObject<EntityType<T>> addRegistry(String name, EntityType.EntityFactory<T> constructor, float sizex, float sizey)
{
public static <T extends Entity> RegistryObject<EntityType<T>> addRegistry(String name, EntityType.EntityFactory<T> constructor, float sizex, float sizey) {
return addRegistry(name, constructor, sizex, sizey, 1);
}
public static <T extends Entity> RegistryObject<EntityType<T>> addRegistry(String name, EntityType.EntityFactory<T> constructor, float sizex, float sizey, int trackingrange)
{
public static <T extends Entity> RegistryObject<EntityType<T>> addRegistry(String name, EntityType.EntityFactory<T> constructor, float sizex, float sizey, int trackingrange) {
return DEFERRED_REGISTER.register(name, () -> EntityType.Builder.of(constructor, MobCategory.MISC).clientTrackingRange(trackingrange).sized(sizex, sizey).build(new ResourceLocation(SiegeMachines.ID, name).toString()));
}
public static void register(IEventBus eventBus)
{
public static void register(IEventBus eventBus) {
DEFERRED_REGISTER.register(eventBus);
}
}

View File

@@ -1,11 +1,10 @@
package ru.magistu.siegemachines.entity;
import ru.magistu.siegemachines.client.gui.machine.crosshair.Crosshair;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import ru.magistu.siegemachines.client.gui.machine.crosshair.Crosshair;
public interface IReloading
{
public interface IReloading {
@OnlyIn(Dist.CLIENT)
Crosshair createCrosshair();
}

View File

@@ -1,22 +1,19 @@
package ru.magistu.siegemachines.entity.projectile;
import com.mojang.math.Vector3d;
import ru.magistu.siegemachines.item.ModItems;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import ru.magistu.siegemachines.item.ModItems;
public class Cannonball extends Missile
{
public Cannonball(EntityType<Cannonball> type, Level level)
{
public class Cannonball extends Missile {
public Cannonball(EntityType<Cannonball> type, Level level) {
super(type, level);
this.item = ModItems.CANNONBALL.get();
}
public Cannonball(EntityType<Cannonball> entitytype, Level level, Vector3d pos, LivingEntity entity, Item item)
{
super(entitytype, level, pos, entity, MissileType.CANNONBALL, item);
}
public Cannonball(EntityType<Cannonball> entitytype, Level level, Vec3 pos, LivingEntity entity, Item item) {
super(entitytype, level, pos, entity, MissileType.CANNONBALL, item);
}
}

View File

@@ -1,7 +1,6 @@
package ru.magistu.siegemachines.entity.projectile;
public enum FlightType
{
public enum FlightType {
NONE,
AHEAD,
SPINNING

View File

@@ -1,42 +1,38 @@
package ru.magistu.siegemachines.entity.projectile;
import com.mojang.math.Vector3d;
import ru.magistu.siegemachines.item.ModItems;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.network.NetworkHooks;
import org.jetbrains.annotations.NotNull;
import ru.magistu.siegemachines.item.ModItems;
public class GiantArrow extends AbstractArrow
{
private final Packet<?> spawningpacket = NetworkHooks.getEntitySpawningPacket(this);
public class GiantArrow extends AbstractArrow {
private final Packet<ClientGamePacketListener> spawningpacket = NetworkHooks.getEntitySpawningPacket(this);
public GiantArrow(EntityType<GiantArrow> type, Level level)
{
public GiantArrow(EntityType<GiantArrow> type, Level level) {
super(type, level);
}
public GiantArrow(EntityType<GiantArrow> entitytype, Level level, Vector3d pos, LivingEntity entity, Item item)
{
super(entitytype, entity, level);
public GiantArrow(EntityType<GiantArrow> entitytype, Level level, Vec3 pos, LivingEntity entity, Item item) {
super(entitytype, entity, level);
this.setPos(pos.x, pos.y, pos.z);
this.setBaseDamage(5.0F);
}
}
@Override
protected @NotNull ItemStack getPickupItem()
{
protected @NotNull ItemStack getPickupItem() {
return new ItemStack(ModItems.GIANT_ARROW.get());
}
@Override
public @NotNull Packet<?> getAddEntityPacket()
{
return spawningpacket;
}
public @NotNull Packet<ClientGamePacketListener> getAddEntityPacket() {
return spawningpacket;
}
}

View File

@@ -1,23 +1,20 @@
package ru.magistu.siegemachines.entity.projectile;
import com.mojang.math.Vector3d;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import ru.magistu.siegemachines.item.ModItems;
public class GiantStone extends Missile
{
public GiantStone(EntityType<GiantStone> entitytype, Level level)
{
super(entitytype, level);
this.item = ModItems.GIANT_STONE.get();
}
public class GiantStone extends Missile {
public GiantStone(EntityType<GiantStone> entitytype, Level level) {
super(entitytype, level);
this.item = ModItems.GIANT_STONE.get();
}
public GiantStone(EntityType<GiantStone> entitytype, Level level, Vector3d pos, LivingEntity entity, Item item)
{
super(entitytype, level, pos, entity, MissileType.GIANT_STONE, item);
}
public GiantStone(EntityType<GiantStone> entitytype, Level level, Vec3 pos, LivingEntity entity, Item item) {
super(entitytype, level, pos, entity, MissileType.GIANT_STONE, item);
}
}

View File

@@ -1,13 +1,12 @@
package ru.magistu.siegemachines.entity.projectile;
import com.mojang.math.Vector3d;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
public interface IProjectileFactory<T extends Projectile>
{
T create(EntityType<T> entitytype, Level level, Vector3d pos, LivingEntity entity, Item item);
public interface IProjectileFactory<T extends Projectile> {
T create(EntityType<T> entitytype, Level level, Vec3 pos, LivingEntity entity, Item item);
}

View File

@@ -1,14 +1,12 @@
package ru.magistu.siegemachines.entity.projectile;
import com.mojang.math.Vector3d;
import net.minecraft.world.level.ExplosionDamageCalculator;
import ru.magistu.siegemachines.item.ModItems;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.BlockParticleOption;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
@@ -23,6 +21,7 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.ShieldItem;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.ExplosionDamageCalculator;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
@@ -32,185 +31,154 @@ import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.network.NetworkHooks;
import org.jetbrains.annotations.NotNull;
import ru.magistu.siegemachines.item.ModItems;
import javax.annotation.Nullable;
public abstract class Missile extends ThrowableItemProjectile
{
public MissileType type = MissileType.STONE;
public Item item = ModItems.STONE.get();
public abstract class Missile extends ThrowableItemProjectile {
public MissileType type = MissileType.STONE;
public Item item = ModItems.STONE.get();
public Missile(EntityType<? extends Missile> entitytype, Level level)
{
super(entitytype, level);
}
public Missile(EntityType<? extends Missile> entitytype, Level level) {
super(entitytype, level);
}
public Missile(EntityType<? extends Missile> entitytype, Level level, Vector3d pos, LivingEntity entity, MissileType type, Item item)
{
super(entitytype, entity, level);
this.type = type;
this.item = item;
this.setPos(pos.x, pos.y, pos.z);
}
public Missile(EntityType<? extends Missile> entitytype, Level level, Vec3 pos, LivingEntity entity, MissileType type, Item item) {
super(entitytype, entity, level);
this.type = type;
this.item = item;
this.setPos(pos.x, pos.y, pos.z);
}
@Override
public @NotNull Item getDefaultItem()
{
return this.item;
}
@Override
public @NotNull Item getDefaultItem() {
return this.item;
}
@Override
public @NotNull Packet<?> getAddEntityPacket()
{
return NetworkHooks.getEntitySpawningPacket(this);
}
@Override
public @NotNull Packet<ClientGamePacketListener> getAddEntityPacket() {
return NetworkHooks.getEntitySpawningPacket(this);
}
@Override
public void onHit(HitResult result)
{
float f = 2.0F;
if (result.getType() == HitResult.Type.ENTITY)
{
EntityHitResult entityRTR = (EntityHitResult)result;
Vec3 pos = entityRTR.getLocation();
Entity entity = entityRTR.getEntity();
float damage = this.type.specs.mass.get() * (float) this.getDeltaMovement().length();
@Override
public void onHit(HitResult result) {
float f = 2.0F;
if (result.getType() == HitResult.Type.ENTITY) {
EntityHitResult entityRTR = (EntityHitResult) result;
Vec3 pos = entityRTR.getLocation();
Entity entity = entityRTR.getEntity();
float damage = this.type.specs.mass.get() * (float) this.getDeltaMovement().length();
DamageSource damagesource = DamageSource.thrown(this, this.getOwner());
if (this.type.armorpiercing >= 1.0f)
{
damagesource = damagesource.bypassArmor();
}
else if (this.type.armorpiercing > 0.0f && entity instanceof LivingEntity livingentity)
{
if(livingentity instanceof Player player) {
if(player.isBlocking() && (item == ModItems.GIANT_ARROW.get() || item == Items.ARROW) && (player.getItemInHand(InteractionHand.MAIN_HAND).getItem() instanceof ShieldItem || player.isBlocking() && player.getItemInHand(InteractionHand.OFF_HAND).getItem() instanceof ShieldItem)) {
return;
}
}
damage -= (1.0f - this.type.armorpiercing) * (damage - CombatRules.getDamageAfterAbsorb(damage, 0, 0));
}
// DamageSource damagesource = DamageSource.thrown(this, this.getOwner()); //TODO
DamageSource damagesource = level().damageSources().thrown(this, this.getOwner());
if (this.type.armorpiercing >= 1.0f) {
// damagesource = damagesource.bypassArmor(); TODO хз что тут
} else if (this.type.armorpiercing > 0.0f && entity instanceof LivingEntity livingentity) {
if (livingentity instanceof Player player) {
if (player.isBlocking() && (item == ModItems.GIANT_ARROW.get() || item == Items.ARROW) && (player.getItemInHand(InteractionHand.MAIN_HAND).getItem() instanceof ShieldItem || player.isBlocking() && player.getItemInHand(InteractionHand.OFF_HAND).getItem() instanceof ShieldItem)) {
return;
}
}
damage -= (1.0f - this.type.armorpiercing) * (damage - CombatRules.getDamageAfterAbsorb(damage, 0, 0));
}
if (!this.level.isClientSide() && this.type.explosive)
{
this.explode(pos.x, pos.y, pos.z, 3.0F, Explosion.BlockInteraction.NONE);
this.remove(RemovalReason.KILLED);
}
if (!this.level().isClientSide() && this.type.explosive) {
this.explode(pos.x, pos.y, pos.z, 3.0F, Explosion.BlockInteraction.KEEP); //TODO
this.remove(RemovalReason.KILLED);
}
entity.hurt(damagesource, damage);
Vec3 vector3d = this.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D).normalize().scale((double) this.type.knockback * 0.6D);
if (vector3d.lengthSqr() > 0.0D)
{
entity.push(vector3d.x, 0.1D, vector3d.z);
}
}
entity.hurt(damagesource, damage);
Vec3 vector3d = this.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D).normalize().scale((double) this.type.knockback * 0.6D);
if (vector3d.lengthSqr() > 0.0D) {
entity.push(vector3d.x, 0.1D, vector3d.z);
}
}
if (result.getType() == HitResult.Type.BLOCK)
{
BlockHitResult blockRTR = (BlockHitResult)result;
BlockPos blockpos = blockRTR.getBlockPos();
BlockState blockstate = this.level.getBlockState(blockpos);
boolean smoothimpact = (blockstate == Blocks.SAND.defaultBlockState() ||
blockstate == Blocks.RED_SAND.defaultBlockState() ||
blockstate == Blocks.DIRT.defaultBlockState() ||
blockstate == Blocks.GRASS_BLOCK.defaultBlockState() ||
blockstate == Blocks.DIRT_PATH.defaultBlockState() ||
blockstate == Blocks.COARSE_DIRT.defaultBlockState() ||
blockstate == Blocks.SNOW_BLOCK.defaultBlockState()) &&
blockRTR.getDirection() == Direction.UP;
if (result.getType() == HitResult.Type.BLOCK) {
BlockHitResult blockRTR = (BlockHitResult) result;
BlockPos blockpos = blockRTR.getBlockPos();
BlockState blockstate = this.level().getBlockState(blockpos);
boolean smoothimpact = (blockstate == Blocks.SAND.defaultBlockState() ||
blockstate == Blocks.RED_SAND.defaultBlockState() ||
blockstate == Blocks.DIRT.defaultBlockState() ||
blockstate == Blocks.GRASS_BLOCK.defaultBlockState() ||
blockstate == Blocks.DIRT_PATH.defaultBlockState() ||
blockstate == Blocks.COARSE_DIRT.defaultBlockState() ||
blockstate == Blocks.SNOW_BLOCK.defaultBlockState()) &&
blockRTR.getDirection() == Direction.UP;
if (blockRTR.getDirection() == Direction.UP)
{
if (this.type.explosive)
{
for (int r = 0; r < this.type.specs.explosionpower.get(); ++r)
{
for (float a = 0; a < 2 * Math.PI; a += Math.PI / 4)
{
BlockPos pos = blockRTR.getBlockPos().offset(r * Math.cos(a), 0, -r * Math.sin(a));
if (this.level.getBlockState(pos) == Blocks.GRASS_BLOCK.defaultBlockState())
{
this.level.setBlockAndUpdate(pos, Blocks.DIRT.defaultBlockState());
}
}
}
}
if (!this.level.isClientSide())
{
this.remove(RemovalReason.KILLED);
if (smoothimpact && this.type.explosive)
{
if (blockRTR.getDirection() == Direction.UP) {
if (this.type.explosive) {
for (int r = 0; r < this.type.specs.explosionpower.get(); ++r) {
for (float a = 0; a < 2 * Math.PI; a += Math.PI / 4) {
BlockPos pos = blockRTR.getBlockPos().offset((int) (r * Math.cos(a)), 0, (int) (-r * Math.sin(a))); //TODO был не int
if (this.level().getBlockState(pos) == Blocks.GRASS_BLOCK.defaultBlockState()) {
this.level().setBlockAndUpdate(pos, Blocks.DIRT.defaultBlockState());
}
}
}
}
if (!this.level().isClientSide()) {
this.remove(RemovalReason.KILLED);
if (smoothimpact && this.type.explosive) {
this.explode(blockpos.getX(), blockpos.getY(), blockpos.getZ(), this.type.specs.explosionpower.get() * f, Explosion.BlockInteraction.NONE);
}
}
else if (smoothimpact)
{
this.dustExplosion(new BlockParticleOption(ParticleTypes.BLOCK, blockstate).setPos(blockpos), blockpos, this.type.specs.explosionpower.get() / 2, 50);
}
}
if (!this.level.isClientSide() && !smoothimpact && this.type.explosive)
{
this.explode(blockpos.getX(), blockpos.getY(), blockpos.getZ(), this.type.specs.explosionpower.get() * f, Explosion.BlockInteraction.BREAK);
}
}
this.explode(blockpos.getX(), blockpos.getY(), blockpos.getZ(), this.type.specs.explosionpower.get() * f, Explosion.BlockInteraction.KEEP); //TODO
}
} else if (smoothimpact) {
this.dustExplosion(new BlockParticleOption(ParticleTypes.BLOCK, blockstate).setPos(blockpos), blockpos, this.type.specs.explosionpower.get() / 2, 50);
}
}
if (!this.level().isClientSide() && !smoothimpact && this.type.explosive) {
this.explode(blockpos.getX(), blockpos.getY(), blockpos.getZ(), this.type.specs.explosionpower.get() * f, Explosion.BlockInteraction.DESTROY);
}
}
if (result.getType() == HitResult.Type.MISS)
{
this.level.playSound((Player)this.getOwner(), this.getOnPos(), SoundEvents.ANVIL_BREAK, SoundSource.AMBIENT, 1.0f, 1.0f);
if(!this.level.isClientSide())
{
this.remove(RemovalReason.KILLED);
}
}
if (!this.level.isClientSide())
{
this.remove(RemovalReason.KILLED);
}
}
if (result.getType() == HitResult.Type.MISS) {
this.level().playSound((Player) this.getOwner(), this.getOnPos(), SoundEvents.ANVIL_BREAK, SoundSource.AMBIENT, 1.0f, 1.0f);
if (!this.level().isClientSide()) {
this.remove(RemovalReason.KILLED);
}
}
if (!this.level().isClientSide()) {
this.remove(RemovalReason.KILLED);
}
}
private void dustExplosion(ParticleOptions particle, BlockPos blockpos, double speed, int amount)
{
this.dustExplosion(particle, blockpos.getX(), blockpos.getY(), blockpos.getZ(), speed, amount);
}
private void dustExplosion(ParticleOptions particle, BlockPos blockpos, double speed, int amount) {
this.dustExplosion(particle, blockpos.getX(), blockpos.getY(), blockpos.getZ(), speed, amount);
}
private void dustExplosion(ParticleOptions particle, double x, double y, double z, double speed, int amount)
{
for (int i = 0; i < amount; ++i)
{
Vec3 movement = this.getDeltaMovement();
double d0 = x - 0.05 + this.level.random.nextDouble() * 0.3;
double d1 = y + 1.0;
double d2 = z - 0.05 + this.level.random.nextDouble() * 0.3;
double d3 = movement.x * this.level.random.nextDouble() * speed;
double d4 = -movement.y * this.level.random.nextDouble() * speed * 10.0f;
double d5 = movement.z * this.level.random.nextDouble() * speed;
this.level.addParticle(particle, d0, d1, d2, d3, d4, d5);
}
}
private void dustExplosion(ParticleOptions particle, double x, double y, double z, double speed, int amount) {
for (int i = 0; i < amount; ++i) {
Vec3 movement = this.getDeltaMovement();
double d0 = x - 0.05 + this.level().random.nextDouble() * 0.3;
double d1 = y + 1.0;
double d2 = z - 0.05 + this.level().random.nextDouble() * 0.3;
double d3 = movement.x * this.level().random.nextDouble() * speed;
double d4 = -movement.y * this.level().random.nextDouble() * speed * 10.0f;
double d5 = movement.z * this.level().random.nextDouble() * speed;
this.level().addParticle(particle, d0, d1, d2, d3, d4, d5);
}
}
@Override
public void tick()
{
if (this.type.flighttype == FlightType.SPINNING)
{
this.setXRot(this.getXRot() + 0.5f);
}
@Override
public void tick() {
if (this.type.flighttype == FlightType.SPINNING) {
this.setXRot(this.getXRot() + 0.5f);
}
super.tick();
}
super.tick();
}
public MissileExplosion explode(double x, double y, double z, float radius, Explosion.BlockInteraction mode)
{
return this.explode(null, null, x, y, z, radius, false, mode);
}
public MissileExplosion explode(double x, double y, double z, float radius, Explosion.BlockInteraction mode) {
return this.explode(null, null, x, y, z, radius, false, mode);
}
public MissileExplosion explode(@Nullable DamageSource source, @Nullable ExplosionDamageCalculator context, double x, double y, double z, float size, boolean fired, Explosion.BlockInteraction mode)
{
MissileExplosion explosion = new MissileExplosion(this.level, this.getOwner(), source, context, x, y, z, size, fired, mode);
if (net.minecraftforge.event.ForgeEventFactory.onExplosionStart(level, explosion)) return explosion;
explosion.explode();
explosion.finalizeExplosion(true);
return explosion;
}
public MissileExplosion explode(@Nullable DamageSource source, @Nullable ExplosionDamageCalculator context, double x, double y, double z, float size, boolean fired, Explosion.BlockInteraction mode) {
MissileExplosion explosion = new MissileExplosion(this.level(), this.getOwner(), source, context, x, y, z, size, fired, mode);
if (net.minecraftforge.event.ForgeEventFactory.onExplosionStart(level(), explosion)) return explosion;
explosion.explode();
explosion.finalizeExplosion(true);
return explosion;
}
}

View File

@@ -17,7 +17,6 @@ import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.item.PrimedTnt;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.ProtectionEnchantment;
import net.minecraft.world.level.*;
@@ -27,7 +26,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.HitResult;
@@ -37,394 +36,327 @@ import ru.magistu.siegemachines.entity.machine.Machine;
import javax.annotation.Nullable;
import java.util.*;
public class MissileExplosion extends Explosion
{
private static final ExplosionDamageCalculator EXPLOSION_DAMAGE_CALCULATOR = new ExplosionDamageCalculator();
private final boolean fire;
private final BlockInteraction blockInteraction;
private final Random random = new Random();
private final Level level;
private final double x;
private final double y;
private final double z;
@Nullable
private final Entity source;
private final float radius;
private final DamageSource damageSource;
private final ExplosionDamageCalculator damageCalculator;
private final List<BlockPos> toBlow = Lists.newArrayList();
private final Map<Player, Vec3> hitPlayers = Maps.newHashMap();
private final Vec3 position;
private float damagemultiplier = 1.0f;
public class MissileExplosion extends Explosion {
private static final ExplosionDamageCalculator EXPLOSION_DAMAGE_CALCULATOR = new ExplosionDamageCalculator();
private final boolean fire;
private final BlockInteraction blockInteraction;
private final Random random = new Random();
private final Level level;
private final double x;
private final double y;
private final double z;
@Nullable
private final Entity source;
private final float radius;
private final DamageSource damageSource;
private final ExplosionDamageCalculator damageCalculator;
private final List<BlockPos> toBlow = Lists.newArrayList();
private final Map<Player, Vec3> hitPlayers = Maps.newHashMap();
private final Vec3 position;
private float damagemultiplier = 1.0f;
public MissileExplosion(Level level, @Nullable Entity source, double x, double y, double z, float radius)
{
this(level, source, x, y, z, radius, false, BlockInteraction.DESTROY);
}
public MissileExplosion(Level level, @Nullable Entity source, double x, double y, double z, float radius) {
this(level, source, x, y, z, radius, false, BlockInteraction.DESTROY);
}
public MissileExplosion(Level level, @Nullable Entity source, double x, double y, double z, float radius, List<BlockPos> pPositions)
{
this(level, source, x, y, z, radius, false, BlockInteraction.DESTROY, pPositions);
}
public MissileExplosion(Level level, @Nullable Entity source, double x, double y, double z, float radius, List<BlockPos> pPositions) {
this(level, source, x, y, z, radius, false, BlockInteraction.DESTROY, pPositions);
}
public MissileExplosion(Level level, @Nullable Entity source, double x, double y, double z, float radius, boolean fired, BlockInteraction blockinteraction, List<BlockPos> pPositions)
{
this(level, source, x, y, z, radius, fired, blockinteraction);
this.toBlow.addAll(pPositions);
}
public MissileExplosion(Level level, @Nullable Entity source, double x, double y, double z, float radius, boolean fired, BlockInteraction blockinteraction, List<BlockPos> pPositions) {
this(level, source, x, y, z, radius, fired, blockinteraction);
this.toBlow.addAll(pPositions);
}
public MissileExplosion(Level level, @Nullable Entity source, double x, double y, double z, float radius, boolean fired, BlockInteraction blockinteraction)
{
this(level, source, null, null, x, y, z, radius, fired, blockinteraction);
}
public MissileExplosion(Level level, @Nullable Entity source, double x, double y, double z, float radius, boolean fired, BlockInteraction blockinteraction) {
this(level, source, null, null, x, y, z, radius, fired, blockinteraction);
}
public MissileExplosion(Level level, @Nullable Entity source, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator damagecalculator, double x, double y, double z, float radius, boolean fired, BlockInteraction blockinteraction)
{
super(level, source, damagesource, damagecalculator, x, y, z, radius, fired, blockinteraction);
this.level = level;
this.source = source;
this.radius = radius;
this.x = x;
this.y = y;
this.z = z;
this.fire = fired;
this.blockInteraction = blockinteraction;
this.damageSource = damagesource == null ? DamageSource.explosion(this) : damagesource;
this.damageCalculator = damagecalculator == null ? this.makeDamageCalculator(source) : damagecalculator;
this.position = new Vec3(this.x, this.y, this.z);
if (source != null && source.isPassenger())
{
Entity vehicle = source.getVehicle();
if (vehicle instanceof Machine)
{
this.damagemultiplier = ((Machine) vehicle).type.specs.damagemultiplier.get();
}
}
}
private ExplosionDamageCalculator makeDamageCalculator(@Nullable Entity pEntity)
{
return pEntity == null ? EXPLOSION_DAMAGE_CALCULATOR : new EntityBasedExplosionDamageCalculator(pEntity);
}
public static float getSeenPercent(Vec3 pExplosionVector, Entity pEntity)
{
AABB aabb = pEntity.getBoundingBox();
double d0 = 1.0D / ((aabb.maxX - aabb.minX) * 2.0D + 1.0D);
double d1 = 1.0D / ((aabb.maxY - aabb.minY) * 2.0D + 1.0D);
double d2 = 1.0D / ((aabb.maxZ - aabb.minZ) * 2.0D + 1.0D);
double d3 = (1.0D - Math.floor(1.0D / d0) * d0) / 2.0D;
double d4 = (1.0D - Math.floor(1.0D / d2) * d2) / 2.0D;
if (!(d0 < 0.0D) && !(d1 < 0.0D) && !(d2 < 0.0D))
{
int i = 0;
int j = 0;
for (double d5 = 0.0D; d5 <= 1.0D; d5 += d0)
{
for (double d6 = 0.0D; d6 <= 1.0D; d6 += d1)
{
for (double d7 = 0.0D; d7 <= 1.0D; d7 += d2)
{
double d8 = Mth.lerp(d5, aabb.minX, aabb.maxX);
double d9 = Mth.lerp(d6, aabb.minY, aabb.maxY);
double d10 = Mth.lerp(d7, aabb.minZ, aabb.maxZ);
Vec3 vec3 = new Vec3(d8 + d3, d9, d10 + d4);
if (pEntity.level.clip(new ClipContext(vec3, pExplosionVector, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, pEntity)).getType() == HitResult.Type.MISS)
{
++i;
}
++j;
}
public MissileExplosion(Level level, @Nullable Entity source, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator damagecalculator, double x, double y, double z, float radius, boolean fired, BlockInteraction blockinteraction) {
super(level, source, damagesource, damagecalculator, x, y, z, radius, fired, blockinteraction);
this.level = level;
this.source = source;
this.radius = radius;
this.x = x;
this.y = y;
this.z = z;
this.fire = fired;
this.blockInteraction = blockinteraction;
// this.damageSource = damagesource == null ? DamageSource.explosion(this) : damagesource; TODO
this.damageSource = damagesource == null ? level.damageSources().explosion(this) : damagesource;
this.damageCalculator = damagecalculator == null ? this.makeDamageCalculator(source) : damagecalculator;
this.position = new Vec3(this.x, this.y, this.z);
if (source != null && source.isPassenger()) {
Entity vehicle = source.getVehicle();
if (vehicle instanceof Machine) {
this.damagemultiplier = ((Machine) vehicle).type.specs.damagemultiplier.get();
}
}
}
}
return (float)i / (float)j;
}
else
{
return 0.0F;
}
}
private ExplosionDamageCalculator makeDamageCalculator(@Nullable Entity pEntity) {
return pEntity == null ? EXPLOSION_DAMAGE_CALCULATOR : new EntityBasedExplosionDamageCalculator(pEntity);
}
/**
* Does the first part of the explosion (destroy blocks)
*/
@Override
public void explode()
{
this.level.gameEvent(this.source, GameEvent.EXPLODE, new BlockPos(this.x, this.y, this.z));
Set<BlockPos> set = Sets.newHashSet();
public static float getSeenPercent(Vec3 pExplosionVector, Entity pEntity) {
AABB aabb = pEntity.getBoundingBox();
double d0 = 1.0D / ((aabb.maxX - aabb.minX) * 2.0D + 1.0D);
double d1 = 1.0D / ((aabb.maxY - aabb.minY) * 2.0D + 1.0D);
double d2 = 1.0D / ((aabb.maxZ - aabb.minZ) * 2.0D + 1.0D);
double d3 = (1.0D - Math.floor(1.0D / d0) * d0) / 2.0D;
double d4 = (1.0D - Math.floor(1.0D / d2) * d2) / 2.0D;
if (!(d0 < 0.0D) && !(d1 < 0.0D) && !(d2 < 0.0D)) {
int i = 0;
int j = 0;
for (int j = 0; j < 16; ++j)
{
for (int k = 0; k < 16; ++k)
{
for (int l = 0; l < 16; ++l)
{
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15)
{
double d0 = (float) j / 15.0F * 2.0F - 1.0F;
double d1 = (float) k / 15.0F * 2.0F - 1.0F;
double d2 = (float) l / 15.0F * 2.0F - 1.0F;
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
d0 /= d3;
d1 /= d3;
d2 /= d3;
float f = this.radius * (0.7F + this.level.random.nextFloat() * 0.6F);
double d4 = this.x;
double d6 = this.y;
double d8 = this.z;
for (double d5 = 0.0D; d5 <= 1.0D; d5 += d0) {
for (double d6 = 0.0D; d6 <= 1.0D; d6 += d1) {
for (double d7 = 0.0D; d7 <= 1.0D; d7 += d2) {
double d8 = Mth.lerp(d5, aabb.minX, aabb.maxX);
double d9 = Mth.lerp(d6, aabb.minY, aabb.maxY);
double d10 = Mth.lerp(d7, aabb.minZ, aabb.maxZ);
Vec3 vec3 = new Vec3(d8 + d3, d9, d10 + d4);
if (pEntity.level().clip(new ClipContext(vec3, pExplosionVector, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, pEntity)).getType() == HitResult.Type.MISS) {
++i;
}
for (; f > 0.0F; f -= 0.22500001F)
{
BlockPos blockpos = new BlockPos(d4, d6, d8);
BlockState blockstate = this.level.getBlockState(blockpos);
FluidState fluidstate = this.level.getFluidState(blockpos);
if (!this.level.isInWorldBounds(blockpos))
{
break;
}
Optional<Float> optional = this.damageCalculator.getBlockExplosionResistance(this, this.level, blockpos, blockstate, fluidstate);
if (optional.isPresent())
{
f -= (optional.get() + 0.3F) * 0.3F;
}
if (f > 0.0F && this.damageCalculator.shouldBlockExplode(this, this.level, blockpos, blockstate, f))
{
set.add(blockpos);
}
d4 += d0 * (double)0.3F;
d6 += d1 * (double)0.3F;
d8 += d2 * (double)0.3F;
}
}
++j;
}
}
}
}
}
this.toBlow.addAll(set);
float f2 = this.radius * 2.0F;
int k1 = Mth.floor(this.x - (double)f2 - 1.0D);
int l1 = Mth.floor(this.x + (double)f2 + 1.0D);
int i2 = Mth.floor(this.y - (double)f2 - 1.0D);
int i1 = Mth.floor(this.y + (double)f2 + 1.0D);
int j2 = Mth.floor(this.z - (double)f2 - 1.0D);
int j1 = Mth.floor(this.z + (double)f2 + 1.0D);
List<Entity> list = this.level.getEntities(this.source, new AABB(k1, i2, j2, l1, i1, j1));
net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate(this.level, this, list, f2);
Vec3 vec3 = new Vec3(this.x, this.y, this.z);
return (float) i / (float) j;
} else {
return 0.0F;
}
}
for (Entity entity : list)
{
if (!entity.ignoreExplosion())
{
double d12 = Math.sqrt(entity.distanceToSqr(vec3)) / (double) f2;
if (d12 <= 1.0D)
{
double d5 = entity.getX() - this.x;
double d7 = (entity instanceof PrimedTnt ? entity.getY() : entity.getEyeY()) - this.y;
double d9 = entity.getZ() - this.z;
double d13 = Math.sqrt(d5 * d5 + d7 * d7 + d9 * d9);
if (d13 != 0.0D)
{
d5 /= d13;
d7 /= d13;
d9 /= d13;
double d14 = getSeenPercent(vec3, entity);
double d10 = (1.0D - d12) * d14;
entity.hurt(this.getDamageSource(), this.damagemultiplier * (int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f2 + 1.0D));
double d11 = d10;
if (entity instanceof LivingEntity)
{
d11 = ProtectionEnchantment.getExplosionKnockbackAfterDampener((LivingEntity) entity, d10);
}
/**
* Does the first part of the explosion (destroy blocks)
*/
@Override
public void explode() {
this.level.gameEvent(this.source, GameEvent.EXPLODE, new BlockPos((int) this.x, (int) this.y, (int) this.z));
Set<BlockPos> set = Sets.newHashSet();
entity.setDeltaMovement(entity.getDeltaMovement().add(d5 * d11, d7 * d11, d9 * d11));
if (entity instanceof Player)
{
Player player = (Player) entity;
if (!player.isSpectator() && (!player.isCreative() || !player.getAbilities().flying))
{
this.hitPlayers.put(player, new Vec3(d5 * d10, d7 * d10, d9 * d10));
}
}
}
for (int j = 0; j < 16; ++j) {
for (int k = 0; k < 16; ++k) {
for (int l = 0; l < 16; ++l) {
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
double d0 = (float) j / 15.0F * 2.0F - 1.0F;
double d1 = (float) k / 15.0F * 2.0F - 1.0F;
double d2 = (float) l / 15.0F * 2.0F - 1.0F;
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
d0 /= d3;
d1 /= d3;
d2 /= d3;
float f = this.radius * (0.7F + this.level.random.nextFloat() * 0.6F);
double d4 = this.x;
double d6 = this.y;
double d8 = this.z;
for (; f > 0.0F; f -= 0.22500001F) {
BlockPos blockpos = new BlockPos((int) d4, (int) d6, (int) d8); //TODO
BlockState blockstate = this.level.getBlockState(blockpos);
FluidState fluidstate = this.level.getFluidState(blockpos);
if (!this.level.isInWorldBounds(blockpos)) {
break;
}
Optional<Float> optional = this.damageCalculator.getBlockExplosionResistance(this, this.level, blockpos, blockstate, fluidstate);
if (optional.isPresent()) {
f -= (optional.get() + 0.3F) * 0.3F;
}
if (f > 0.0F && this.damageCalculator.shouldBlockExplode(this, this.level, blockpos, blockstate, f)) {
set.add(blockpos);
}
d4 += d0 * (double) 0.3F;
d6 += d1 * (double) 0.3F;
d8 += d2 * (double) 0.3F;
}
}
}
}
}
}
}
}
this.toBlow.addAll(set);
float f2 = this.radius * 2.0F;
int k1 = Mth.floor(this.x - (double) f2 - 1.0D);
int l1 = Mth.floor(this.x + (double) f2 + 1.0D);
int i2 = Mth.floor(this.y - (double) f2 - 1.0D);
int i1 = Mth.floor(this.y + (double) f2 + 1.0D);
int j2 = Mth.floor(this.z - (double) f2 - 1.0D);
int j1 = Mth.floor(this.z + (double) f2 + 1.0D);
List<Entity> list = this.level.getEntities(this.source, new AABB(k1, i2, j2, l1, i1, j1));
net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate(this.level, this, list, f2);
Vec3 vec3 = new Vec3(this.x, this.y, this.z);
/**
* Does the second part of the explosion (sound, particles, drop spawn)
*/
@Override
public void finalizeExplosion(boolean pSpawnParticles)
{
if (this.level.isClientSide)
{
this.level.playLocalSound(this.x, this.y, this.z, SoundEvents.GENERIC_EXPLODE, SoundSource.BLOCKS, 4.0F, (1.0F + (this.level.random.nextFloat() - this.level.random.nextFloat()) * 0.2F) * 0.7F, false);
}
for (Entity entity : list) {
if (!entity.ignoreExplosion()) {
double d12 = Math.sqrt(entity.distanceToSqr(vec3)) / (double) f2;
if (d12 <= 1.0D) {
double d5 = entity.getX() - this.x;
double d7 = (entity instanceof PrimedTnt ? entity.getY() : entity.getEyeY()) - this.y;
double d9 = entity.getZ() - this.z;
double d13 = Math.sqrt(d5 * d5 + d7 * d7 + d9 * d9);
if (d13 != 0.0D) {
d5 /= d13;
d7 /= d13;
d9 /= d13;
double d14 = getSeenPercent(vec3, entity);
double d10 = (1.0D - d12) * d14;
entity.hurt(this.getDamageSource(), this.damagemultiplier * (int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f2 + 1.0D));
double d11 = d10;
if (entity instanceof LivingEntity) {
d11 = ProtectionEnchantment.getExplosionKnockbackAfterDampener((LivingEntity) entity, d10);
}
boolean flag = this.blockInteraction != BlockInteraction.NONE;
if (pSpawnParticles)
{
if (!(this.radius < 2.0F) && flag)
{
this.level.addParticle(ParticleTypes.EXPLOSION_EMITTER, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
}
else
{
this.level.addParticle(ParticleTypes.EXPLOSION, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
}
}
if (flag)
{
ObjectArrayList<Pair<ItemStack, BlockPos>> objectarraylist = new ObjectArrayList<>();
Collections.shuffle(this.toBlow, new Random(this.level.random.nextInt()));
for (BlockPos blockpos : this.toBlow)
{
BlockState blockstate = this.level.getBlockState(blockpos);
Block block = blockstate.getBlock();
if (!blockstate.isAir())
{
BlockPos blockpos1 = blockpos.immutable();
this.level.getProfiler().push("explosion_blocks");
if (blockstate.canDropFromExplosion(this.level, blockpos, this) && this.level instanceof ServerLevel)
{
BlockEntity blockentity = blockstate.hasBlockEntity() ? this.level.getBlockEntity(blockpos) : null;
LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerLevel)this.level)).withRandom(this.level.random).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(blockpos)).withParameter(LootContextParams.TOOL, ItemStack.EMPTY).withOptionalParameter(LootContextParams.BLOCK_ENTITY, blockentity).withOptionalParameter(LootContextParams.THIS_ENTITY, this.source);
if (this.blockInteraction == BlockInteraction.DESTROY)
{
lootcontext$builder.withParameter(LootContextParams.EXPLOSION_RADIUS, this.radius);
}
blockstate.getDrops(lootcontext$builder).forEach((p_46074_) -> {
addBlockDrops(objectarraylist, p_46074_, blockpos1);
});
}
blockstate.onBlockExploded(this.level, blockpos, this);
this.level.getProfiler().pop();
entity.setDeltaMovement(entity.getDeltaMovement().add(d5 * d11, d7 * d11, d9 * d11));
if (entity instanceof Player) {
Player player = (Player) entity;
if (!player.isSpectator() && (!player.isCreative() || !player.getAbilities().flying)) {
this.hitPlayers.put(player, new Vec3(d5 * d10, d7 * d10, d9 * d10));
}
}
}
}
}
}
}
for (Pair<ItemStack, BlockPos> pair : objectarraylist)
{
Block.popResource(this.level, pair.getSecond(), pair.getFirst());
}
}
}
if (this.fire)
{
for (BlockPos blockpos2 : this.toBlow)
{
if (this.random.nextInt(3) == 0 && this.level.getBlockState(blockpos2).isAir() && this.level.getBlockState(blockpos2.below()).isSolidRender(this.level, blockpos2.below()))
{
this.level.setBlockAndUpdate(blockpos2, BaseFireBlock.getState(this.level, blockpos2));
/**
* Does the second part of the explosion (sound, particles, drop spawn)
*/
@Override
public void finalizeExplosion(boolean pSpawnParticles) {
if (this.level.isClientSide) {
this.level.playLocalSound(this.x, this.y, this.z, SoundEvents.GENERIC_EXPLODE, SoundSource.BLOCKS, 4.0F, (1.0F + (this.level.random.nextFloat() - this.level.random.nextFloat()) * 0.2F) * 0.7F, false);
}
boolean flag = this.blockInteraction != BlockInteraction.KEEP; //TODO
if (pSpawnParticles) {
if (!(this.radius < 2.0F) && flag) {
this.level.addParticle(ParticleTypes.EXPLOSION_EMITTER, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
} else {
this.level.addParticle(ParticleTypes.EXPLOSION, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
}
}
}
}
}
if (flag) {
ObjectArrayList<Pair<ItemStack, BlockPos>> objectarraylist = new ObjectArrayList<>();
Collections.shuffle(this.toBlow, new Random(this.level.random.nextInt()));
private static void addBlockDrops(ObjectArrayList<Pair<ItemStack, BlockPos>> pDropPositionArray, ItemStack pStack, BlockPos pPos)
{
int i = pDropPositionArray.size();
for (BlockPos blockpos : this.toBlow) {
BlockState blockstate = this.level.getBlockState(blockpos);
Block block = blockstate.getBlock();
if (!blockstate.isAir()) {
BlockPos blockpos1 = blockpos.immutable();
this.level.getProfiler().push("explosion_blocks");
if (blockstate.canDropFromExplosion(this.level, blockpos, this) && this.level instanceof ServerLevel) {
BlockEntity blockentity = blockstate.hasBlockEntity() ? this.level.getBlockEntity(blockpos) : null;
LootParams.Builder lootcontext$builder = (new LootParams.Builder((ServerLevel) this.level)).withLuck(this.level.random.nextFloat()).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(blockpos)).withParameter(LootContextParams.TOOL, ItemStack.EMPTY).withOptionalParameter(LootContextParams.BLOCK_ENTITY, blockentity).withOptionalParameter(LootContextParams.THIS_ENTITY, this.source);
if (this.blockInteraction == BlockInteraction.DESTROY) {
lootcontext$builder.withParameter(LootContextParams.EXPLOSION_RADIUS, this.radius);
}
for (int j = 0; j < i; ++j)
{
Pair<ItemStack, BlockPos> pair = pDropPositionArray.get(j);
ItemStack itemstack = pair.getFirst();
if (ItemEntity.areMergable(itemstack, pStack))
{
ItemStack itemstack1 = ItemEntity.merge(itemstack, pStack, 16);
pDropPositionArray.set(j, Pair.of(itemstack1, pair.getSecond()));
if (pStack.isEmpty())
{
return;
blockstate.getDrops(lootcontext$builder).forEach((p_46074_) -> {
addBlockDrops(objectarraylist, p_46074_, blockpos1);
});
}
blockstate.onBlockExploded(this.level, blockpos, this);
this.level.getProfiler().pop();
}
}
}
}
pDropPositionArray.add(Pair.of(pStack, pPos));
}
@Override
public DamageSource getDamageSource()
{
return this.damageSource;
}
@Override
public Map<Player, Vec3> getHitPlayers()
{
return this.hitPlayers;
}
/**
* Returns either the entity that placed the explosive block, the entity that caused the explosion or null.
*/
@Nullable
@Override
public LivingEntity getSourceMob()
{
if (this.source == null)
{
return null;
}
else if (this.source instanceof PrimedTnt)
{
return ((PrimedTnt)this.source).getOwner();
}
else if (this.source instanceof LivingEntity)
{
return (LivingEntity)this.source;
}
else
{
if (this.source instanceof Projectile)
{
Entity entity = ((Projectile)this.source).getOwner();
if (entity instanceof LivingEntity)
{
return (LivingEntity)entity;
for (Pair<ItemStack, BlockPos> pair : objectarraylist) {
Block.popResource(this.level, pair.getSecond(), pair.getFirst());
}
}
}
return null;
}
}
if (this.fire) {
for (BlockPos blockpos2 : this.toBlow) {
if (this.random.nextInt(3) == 0 && this.level.getBlockState(blockpos2).isAir() && this.level.getBlockState(blockpos2.below()).isSolidRender(this.level, blockpos2.below())) {
this.level.setBlockAndUpdate(blockpos2, BaseFireBlock.getState(this.level, blockpos2));
}
}
}
@Override
public void clearToBlow()
{
this.toBlow.clear();
}
}
@Override
public List<BlockPos> getToBlow()
{
return this.toBlow;
}
private static void addBlockDrops(ObjectArrayList<Pair<ItemStack, BlockPos>> pDropPositionArray, ItemStack pStack, BlockPos pPos) {
int i = pDropPositionArray.size();
@Override
public Vec3 getPosition()
{
return this.position;
}
for (int j = 0; j < i; ++j) {
Pair<ItemStack, BlockPos> pair = pDropPositionArray.get(j);
ItemStack itemstack = pair.getFirst();
if (ItemEntity.areMergable(itemstack, pStack)) {
ItemStack itemstack1 = ItemEntity.merge(itemstack, pStack, 16);
pDropPositionArray.set(j, Pair.of(itemstack1, pair.getSecond()));
if (pStack.isEmpty()) {
return;
}
}
}
@Nullable
@Override
public Entity getExploder()
{
return this.source;
}
pDropPositionArray.add(Pair.of(pStack, pPos));
}
@Override
public DamageSource getDamageSource() {
return this.damageSource;
}
@Override
public Map<Player, Vec3> getHitPlayers() {
return this.hitPlayers;
}
// /**
// * Returns either the entity that placed the explosive block, the entity that caused the explosion or null.
// */
// @Nullable
// @Override
// public LivingEntity getSourceMob() {
// if (this.source == null) {
// return null;
// } else if (this.source instanceof PrimedTnt) {
// return ((PrimedTnt) this.source).getOwner();
// } else if (this.source instanceof LivingEntity) {
// return (LivingEntity) this.source;
// } else {
// if (this.source instanceof Projectile) {
// Entity entity = ((Projectile) this.source).getOwner();
// if (entity instanceof LivingEntity) {
// return (LivingEntity) entity;
// }
// }
//
// return null;
// }
// }
@Override
public void clearToBlow() {
this.toBlow.clear();
}
@Override
public List<BlockPos> getToBlow() {
return this.toBlow;
}
@Override
public Vec3 getPosition() {
return this.position;
}
@Nullable
@Override
public Entity getExploder() {
return this.source;
}
}

View File

@@ -3,12 +3,10 @@ package ru.magistu.siegemachines.entity.projectile;
import ru.magistu.siegemachines.config.MissileSpecs;
import ru.magistu.siegemachines.config.SpecsConfig;
public enum MissileType
{
public enum MissileType {
CANNONBALL(SpecsConfig.CANNONBALL, 1.5f, true, FlightType.SPINNING, 1.0f),
STONE(SpecsConfig.STONE, 1.5f, true, FlightType.SPINNING, 1.0f),
GIANT_STONE(SpecsConfig.GIANT_STONE, 3.0f, true, FlightType.SPINNING, 1.0f);
//GIANT_ARROW(SpecsConfig.GIANT_ARROW, 1.5f, false, FlightType.AHEAD, 0.5f);
public final MissileSpecs specs;
public final float knockback;
@@ -16,8 +14,7 @@ public enum MissileType
public final FlightType flighttype;
public final float armorpiercing;
MissileType(MissileSpecs specs, float knockback, boolean explosive, FlightType headingtype, float armorpiercing)
{
MissileType(MissileSpecs specs, float knockback, boolean explosive, FlightType headingtype, float armorpiercing) {
this.specs = specs;
this.knockback = knockback;
this.explosive = explosive;

View File

@@ -1,19 +1,18 @@
package ru.magistu.siegemachines.entity.projectile;
import com.mojang.math.Vector3d;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import ru.magistu.siegemachines.entity.EntityTypes;
import ru.magistu.siegemachines.item.ModItems;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.Arrow;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import ru.magistu.siegemachines.entity.EntityTypes;
import ru.magistu.siegemachines.item.ModItems;
public class ProjectileBuilder<T extends Projectile>
{
public class ProjectileBuilder<T extends Projectile> {
public final static ProjectileBuilder<Stone> NONE = new ProjectileBuilder<>(Items.AIR, EntityTypes.STONE.get(), Stone::new);
public final static ProjectileBuilder<?>[] NO_AMMO = new ProjectileBuilder[]{};
@@ -37,21 +36,18 @@ public class ProjectileBuilder<T extends Projectile>
public final EntityType<T> entitytype;
public final IProjectileFactory<T> factory;
public ProjectileBuilder(Item item, EntityType<T> entitytype, IProjectileFactory<T> factory)
{
public ProjectileBuilder(Item item, EntityType<T> entitytype, IProjectileFactory<T> factory) {
this(item, item, entitytype, factory);
}
public ProjectileBuilder(Item item, Item projectilitem, EntityType<T> entitytype, IProjectileFactory<T> factory)
{
public ProjectileBuilder(Item item, Item projectilitem, EntityType<T> entitytype, IProjectileFactory<T> factory) {
this.item = item;
this.projectilitem = projectilitem;
this.entitytype = entitytype;
this.factory = factory;
}
public T build(Level level, Vector3d pos, LivingEntity entity)
{
public T build(Level level, Vec3 pos, LivingEntity entity) {
return this.factory.create(this.entitytype, level, pos, entity, this.item);
}
}

View File

@@ -1,22 +1,19 @@
package ru.magistu.siegemachines.entity.projectile;
import com.mojang.math.Vector3d;
import ru.magistu.siegemachines.item.ModItems;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import ru.magistu.siegemachines.item.ModItems;
public class Stone extends Missile
{
public Stone(EntityType<Stone> entitytype, Level level)
{
super(entitytype, level);
this.item = ModItems.STONE.get();
}
public class Stone extends Missile {
public Stone(EntityType<Stone> entitytype, Level level) {
super(entitytype, level);
this.item = ModItems.STONE.get();
}
public Stone(EntityType<Stone> entitytype, Level level, Vector3d pos, LivingEntity entity, Item item)
{
super(entitytype, level, pos, entity, MissileType.STONE, item);
}
public Stone(EntityType<Stone> entitytype, Level level, Vec3 pos, LivingEntity entity, Item item) {
super(entitytype, level, pos, entity, MissileType.STONE, item);
}
}

View File

@@ -9,16 +9,21 @@ import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.stats.Stats;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.*;
import net.minecraft.world.level.BaseSpawner;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
@@ -39,10 +44,10 @@ import ru.magistu.siegemachines.client.renderer.MachineItemGeoRenderer;
import ru.magistu.siegemachines.entity.machine.Machine;
import ru.magistu.siegemachines.entity.machine.MachineType;
import ru.magistu.siegemachines.entity.projectile.ProjectileBuilder;
import software.bernie.geckolib3.core.IAnimatable;
import software.bernie.geckolib3.core.manager.AnimationData;
import software.bernie.geckolib3.core.manager.AnimationFactory;
import software.bernie.geckolib3.util.GeckoLibUtil;
import software.bernie.geckolib.core.animatable.GeoAnimatable;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.core.animation.AnimatableManager;
import software.bernie.geckolib.util.GeckoLibUtil;
import javax.annotation.Nullable;
import java.util.List;
@@ -50,40 +55,33 @@ import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Supplier;
public class MachineItem<T extends Machine> extends Item implements IAnimatable
{
private final AnimationFactory factory = GeckoLibUtil.createFactory(this);
public class MachineItem<T extends Machine> extends Item implements GeoAnimatable {
private final AnimatableInstanceCache factory = GeckoLibUtil.createInstanceCache(this);
private final Supplier<EntityType<T>> entitytype;
private final Supplier<MachineType> machinetype;
public MachineItem(Properties prop, Supplier<EntityType<T>> entitytype, Supplier<MachineType> machinetype)
{
public MachineItem(Properties prop, Supplier<EntityType<T>> entitytype, Supplier<MachineType> machinetype) {
super(prop.stacksTo(1));
this.entitytype = entitytype;
this.machinetype = machinetype;
}
@OnlyIn(Dist.CLIENT)
public MachineItemGeoRenderer<T> getRenderer()
{
public MachineItemGeoRenderer<T> getRenderer() {
return null;
}
@Override
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltip, TooltipFlag flag)
{
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltip, TooltipFlag flag) {
if (KeyBindings.getUseKey(this.machinetype.get()) != null)
tooltip.add(Component.translatable(SiegeMachines.ID + ".usage", KeyBindings.getUseKey(this.machinetype.get()).getKey().getDisplayName()).withStyle(ChatFormatting.BLUE));
ProjectileBuilder<?>[] ammo = this.machinetype.get().ammo;
if (ammo.length > 0)
{
if (ammo.length > 0) {
tooltip.add(Component.translatable(SiegeMachines.ID + ".ammo").withStyle(ChatFormatting.BLUE));
for (ProjectileBuilder<?> builder : ammo)
{
if (this.machinetype.get().usesgunpowder)
{
for (ProjectileBuilder<?> builder : ammo) {
if (this.machinetype.get().usesgunpowder) {
tooltip.add(Component.translatable(SiegeMachines.ID + ".uses_gunpowder").withStyle(ChatFormatting.BLUE));
}
tooltip.add(Component.literal(" ").append(Component.translatable(builder.item.getDescriptionId())).withStyle(ChatFormatting.BLUE));
@@ -94,35 +92,30 @@ public class MachineItem<T extends Machine> extends Item implements IAnimatable
@Override
public void initializeClient(Consumer<IClientItemExtensions> consumer) {
super.initializeClient(consumer);
consumer.accept(new IClientItemExtensions()
{
consumer.accept(new IClientItemExtensions() {
@Override
public BlockEntityWithoutLevelRenderer getCustomRenderer()
{
public BlockEntityWithoutLevelRenderer getCustomRenderer() {
return MachineItem.this.getRenderer();
}
});
}
@Override
public @NotNull InteractionResult useOn(UseOnContext context)
{
public @NotNull InteractionResult useOn(UseOnContext context) {
Level world = context.getLevel();
if (!(world instanceof ServerLevel))
return InteractionResult.SUCCESS;
ItemStack itemstack = context.getItemInHand();
BlockPos blockpos = context.getClickedPos();
Direction direction = context.getClickedFace();
BlockState blockstate = world.getBlockState(blockpos);
if (blockstate.is(Blocks.SPAWNER))
{
if (blockstate.is(Blocks.SPAWNER)) {
BlockEntity tileentity = world.getBlockEntity(blockpos);
if (tileentity instanceof SpawnerBlockEntity)
{
BaseSpawner abstractspawner = ((SpawnerBlockEntity)tileentity).getSpawner();
if (tileentity instanceof SpawnerBlockEntity) {
BaseSpawner abstractspawner = ((SpawnerBlockEntity) tileentity).getSpawner();
EntityType<T> entitytype1 = this.getType(itemstack.getTag());
abstractspawner.setEntityId(entitytype1);
abstractspawner.setEntityId(entitytype1, world, RandomSource.create().fork(), blockpos); //RandomSource возможно не такой
tileentity.setChanged();
world.sendBlockUpdated(blockpos, blockstate, blockstate, 3);
itemstack.shrink(1);
@@ -138,9 +131,8 @@ public class MachineItem<T extends Machine> extends Item implements IAnimatable
EntityType<T> entitytype = this.getType(itemstack.getTag());
Machine entity = this.spawn(entitytype, (ServerLevel) world, itemstack, context.getPlayer(), blockpos2, MobSpawnType.SPAWN_EGG, true, !Objects.equals(blockpos, blockpos2) && direction == Direction.UP, context.getRotation());
if (entity != null)
{
if (entity != null) {
entity.deploymentticks = 200;
itemstack.shrink(1);
}
@@ -148,8 +140,7 @@ public class MachineItem<T extends Machine> extends Item implements IAnimatable
return InteractionResult.CONSUME;
}
protected static double getYOffset(LevelReader reader, BlockPos pos, boolean bl, AABB aabb)
{
protected static double getYOffset(LevelReader reader, BlockPos pos, boolean bl, AABB aabb) {
AABB axisalignedbb = new AABB(pos);
if (bl)
axisalignedbb = axisalignedbb.expandTowards(0.0D, -1.0D, 0.0D);
@@ -159,38 +150,43 @@ public class MachineItem<T extends Machine> extends Item implements IAnimatable
}
@Nullable
public Machine spawn(EntityType<T> entitytype, ServerLevel level, @Nullable ItemStack stack, @Nullable Player player, BlockPos pos, MobSpawnType type, boolean bl, boolean bl2, float yaw)
{
public Machine spawn(EntityType<T> entitytype, ServerLevel level, @Nullable ItemStack stack, @Nullable Player player, BlockPos pos, MobSpawnType type, boolean bl, boolean bl2, float yaw) {
return this.spawn(entitytype, level, stack == null ? null : stack.getTag(), stack != null && stack.hasCustomHoverName() ? stack.getHoverName() : null, player, pos, type, bl, bl2, yaw);
}
@Nullable
public Machine spawn(EntityType<T> entitytype, ServerLevel level, @Nullable CompoundTag nbt, @Nullable Component component, @Nullable Player player, BlockPos pos, MobSpawnType type, boolean bl, boolean bl2, float yaw)
{
public Machine spawn(EntityType<T> entitytype, ServerLevel level, @Nullable CompoundTag nbt, @Nullable Component component, @Nullable Player player, BlockPos pos, MobSpawnType type, boolean bl, boolean bl2, float yaw) {
Machine machine = this.create(entitytype, level, nbt, component, player, pos, type, bl, bl2, yaw);
if (machine != null)
{
if (net.minecraftforge.event.ForgeEventFactory.doSpecialSpawn(machine, (LevelAccessor)level, pos.getX(), pos.getY(), pos.getZ(), null, type)) return null;
if (machine != null) {
level.addFreshEntityWithPassengers(machine);
}
return machine;
}
// @Nullable
// public Machine spawn(EntityType<T> entitytype, ServerLevel level, @Nullable CompoundTag nbt, @Nullable Component component, @Nullable Player player, BlockPos pos, MobSpawnType type, boolean bl, boolean bl2, float yaw) {
// Machine machine = this.create(entitytype, level, nbt, component, player, pos, type, bl, bl2, yaw);
// if (machine != null) {
// if (ForgeEventFactory.doSpecialSpawn(machine, (LevelAccessor) level, pos.getX(), pos.getY(), pos.getZ(), null, type))
// return null;
// level.addFreshEntityWithPassengers(machine);
// }
//
// return machine;
// }
@Nullable
public Machine create(EntityType<T> entitytype, ServerLevel level, @Nullable CompoundTag nbt, @Nullable Component component, @Nullable Player player, BlockPos pos, MobSpawnType type, boolean bl, boolean bl2, float yaw)
{
public Machine create(EntityType<T> entitytype, ServerLevel level, @Nullable CompoundTag nbt, @Nullable Component component, @Nullable Player player, BlockPos pos, MobSpawnType type, boolean bl, boolean bl2, float yaw) {
Machine machine = entitytype.create(level);
if (machine == null)
if (machine == null)
return null;
double d0;
if (bl)
{
machine.setPos((double)pos.getX() + 0.5D, pos.getY() + 1, (double)pos.getZ() + 0.5D);
if (bl) {
machine.setPos((double) pos.getX() + 0.5D, pos.getY() + 1, (double) pos.getZ() + 0.5D);
d0 = getYOffset(level, pos, bl2, machine.getBoundingBox());
}
else
} else
d0 = 0.0D;
EntityType.updateCustomEntityTag(level, player, machine, nbt);
@@ -198,7 +194,7 @@ public class MachineItem<T extends Machine> extends Item implements IAnimatable
if (component != null)
machine.setCustomName(component);
machine.moveTo((double)pos.getX() + 0.5D, (double)pos.getY() + d0, (double)pos.getZ() + 0.5D, Mth.wrapDegrees(yaw), 0.0F);
machine.moveTo((double) pos.getX() + 0.5D, (double) pos.getY() + d0, (double) pos.getZ() + 0.5D, Mth.wrapDegrees(yaw), 0.0F);
machine.yHeadRot = machine.getYRot();
machine.yBodyRot = machine.getYRot();
machine.finalizeSpawn(level, level.getCurrentDifficultyAt(machine.blockPosition()), type, null, nbt);
@@ -208,48 +204,41 @@ public class MachineItem<T extends Machine> extends Item implements IAnimatable
}
@Override
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level level, Player player, @NotNull InteractionHand hand)
{
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level level, Player player, @NotNull InteractionHand hand) {
ItemStack itemstack = player.getItemInHand(hand);
BlockHitResult raytraceresult = getPlayerPOVHitResult(level, player, ClipContext.Fluid.SOURCE_ONLY);
if (raytraceresult.getType() != HitResult.Type.BLOCK)
return InteractionResultHolder.pass(itemstack);
if (!(level instanceof ServerLevel))
return InteractionResultHolder.success(itemstack);
BlockPos blockpos = raytraceresult.getBlockPos();
if (!(level.getBlockState(blockpos).getBlock() instanceof IFluidBlock))
return InteractionResultHolder.pass(itemstack);
if (level.mayInteract(player, blockpos) && player.mayUseItemAt(blockpos, raytraceresult.getDirection(), itemstack))
{
if (level.mayInteract(player, blockpos) && player.mayUseItemAt(blockpos, raytraceresult.getDirection(), itemstack)) {
EntityType<T> entitytype = this.getType(itemstack.getTag());
Machine machine = this.spawn(entitytype, (ServerLevel) level, itemstack, player, blockpos, MobSpawnType.SPAWN_EGG, false, false, player.getYRot());
if (machine != null)
{
if (machine != null) {
machine.deploymentticks = 200;
if (!player.isCreative())
itemstack.shrink(1);
player.awardStat(Stats.ITEM_USED.get(this));
return InteractionResultHolder.consume(itemstack);
}
else
} else
return InteractionResultHolder.pass(itemstack);
}
else
} else
return InteractionResultHolder.fail(itemstack);
}
@SuppressWarnings("unchecked")
public EntityType<T> getType(@Nullable CompoundTag nbt)
{
public EntityType<T> getType(@Nullable CompoundTag nbt) {
EntityType<T> defaulttype = this.entitytype.get();
if (nbt != null && nbt.contains("EntityTag", 10))
{
if (nbt != null && nbt.contains("EntityTag", 10)) {
CompoundTag compoundnbt = nbt.getCompound("EntityTag");
if (compoundnbt.contains("id", 8))
return (EntityType<T>) EntityType.byString(compoundnbt.getString("id")).orElse(defaulttype);
@@ -259,14 +248,16 @@ public class MachineItem<T extends Machine> extends Item implements IAnimatable
}
@Override
public void registerControllers(AnimationData data)
{
public void registerControllers(AnimatableManager.ControllerRegistrar controllerRegistrar) {
}
@Override
public AnimationFactory getFactory()
{
public AnimatableInstanceCache getAnimatableInstanceCache() {
return this.factory;
}
@Override
public double getTick(Object o) { //Я хз что это
return 0;
}
}

View File

@@ -11,14 +11,13 @@ import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import ru.magistu.siegemachines.SiegeMachines;
import ru.magistu.siegemachines.client.renderer.*;
import ru.magistu.siegemachines.client.renderer.MachineItemGeoRenderer;
import ru.magistu.siegemachines.client.renderer.model.MachineItemModel;
import ru.magistu.siegemachines.entity.EntityTypes;
import ru.magistu.siegemachines.entity.machine.*;
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModItems
{
public class ModItems {
public static final CreativeModeTab GROUP_SM = new CreativeModeTab(SiegeMachines.ID + ".medieval_siege_machines") {
@Override
public ItemStack makeIcon() {
@@ -28,34 +27,68 @@ public class ModItems
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, SiegeMachines.ID);
public static final RegistryObject<Item> MORTAR = ITEMS.register("mortar", () -> new MachineItem<>(new Item.Properties().tab(ModItems.GROUP_SM), EntityTypes.MORTAR, () -> MachineType.MORTAR)
{@Override @OnlyIn(Dist.CLIENT) public MachineItemGeoRenderer<Mortar> getRenderer() {return new MachineItemGeoRenderer<>(new MachineItemModel<>("mortar"));}});
public static final RegistryObject<Item> CULVERIN = ITEMS.register("culverin", () -> new MachineItem<>(new Item.Properties().tab(ModItems.GROUP_SM), EntityTypes.CULVERIN, () -> MachineType.CULVERIN)
{@Override @OnlyIn(Dist.CLIENT) public MachineItemGeoRenderer<Culverin> getRenderer() {return new MachineItemGeoRenderer<>(new MachineItemModel<>("culverin"));}});
public static final RegistryObject<Item> CATAPULT = ITEMS.register("catapult", () -> new MachineItem<>(new Item.Properties().tab(ModItems.GROUP_SM), EntityTypes.CATAPULT, () -> MachineType.CATAPULT)
{@Override @OnlyIn(Dist.CLIENT) public MachineItemGeoRenderer<Catapult> getRenderer() {return new MachineItemGeoRenderer<>(new MachineItemModel<>("catapult"));}});
public static final RegistryObject<Item> TREBUCHET = ITEMS.register("trebuchet", () -> new MachineItem<>(new Item.Properties().tab(ModItems.GROUP_SM), EntityTypes.TREBUCHET, () -> MachineType.TREBUCHET)
{@Override @OnlyIn(Dist.CLIENT) public MachineItemGeoRenderer<Trebuchet> getRenderer() {return new MachineItemGeoRenderer<>(new MachineItemModel<>("trebuchet"));}});
public static final RegistryObject<Item> BALLISTA = ITEMS.register("ballista", () -> new MachineItem<>(new Item.Properties().tab(ModItems.GROUP_SM), EntityTypes.BALLISTA, () -> MachineType.BALLISTA)
{@Override @OnlyIn(Dist.CLIENT) public MachineItemGeoRenderer<Ballista> getRenderer() {return new MachineItemGeoRenderer<>(new MachineItemModel<>("ballista"));}});
public static final RegistryObject<Item> BATTERING_RAM = ITEMS.register("battering_ram", () -> new MachineItem<>(new Item.Properties().tab(ModItems.GROUP_SM), EntityTypes.BATTERING_RAM, () -> MachineType.BATTERING_RAM)
{@Override @OnlyIn(Dist.CLIENT) public MachineItemGeoRenderer<BatteringRam> getRenderer() {return new MachineItemGeoRenderer<>(new MachineItemModel<>("battering_ram"));}});
public static final RegistryObject<Item> SIEGE_LADDER = ITEMS.register("siege_ladder", () -> new MachineItem<>(new Item.Properties().tab(ModItems.GROUP_SM), EntityTypes.SIEGE_LADDER, () -> MachineType.SIEGE_LADDER)
{@Override @OnlyIn(Dist.CLIENT) public MachineItemGeoRenderer<SiegeLadder> getRenderer() {return new MachineItemGeoRenderer<>(new MachineItemModel<>("siege_ladder"));}});
public static final RegistryObject<Item> MORTAR = ITEMS.register("mortar", () -> new MachineItem<>(new Item.Properties(), EntityTypes.MORTAR, () -> MachineType.MORTAR) {
@Override
@OnlyIn(Dist.CLIENT)
public MachineItemGeoRenderer<Mortar> getRenderer() {
return new MachineItemGeoRenderer<>(new MachineItemModel<>("mortar"));
}
});
public static final RegistryObject<Item> CULVERIN = ITEMS.register("culverin", () -> new MachineItem<>(new Item.Properties(), EntityTypes.CULVERIN, () -> MachineType.CULVERIN) {
@Override
@OnlyIn(Dist.CLIENT)
public MachineItemGeoRenderer<Culverin> getRenderer() {
return new MachineItemGeoRenderer<>(new MachineItemModel<>("culverin"));
}
});
public static final RegistryObject<Item> CATAPULT = ITEMS.register("catapult", () -> new MachineItem<>(new Item.Properties(), EntityTypes.CATAPULT, () -> MachineType.CATAPULT) {
@Override
@OnlyIn(Dist.CLIENT)
public MachineItemGeoRenderer<Catapult> getRenderer() {
return new MachineItemGeoRenderer<>(new MachineItemModel<>("catapult"));
}
});
public static final RegistryObject<Item> TREBUCHET = ITEMS.register("trebuchet", () -> new MachineItem<>(new Item.Properties(), EntityTypes.TREBUCHET, () -> MachineType.TREBUCHET) {
@Override
@OnlyIn(Dist.CLIENT)
public MachineItemGeoRenderer<Trebuchet> getRenderer() {
return new MachineItemGeoRenderer<>(new MachineItemModel<>("trebuchet"));
}
});
public static final RegistryObject<Item> BALLISTA = ITEMS.register("ballista", () -> new MachineItem<>(new Item.Properties(), EntityTypes.BALLISTA, () -> MachineType.BALLISTA) {
@Override
@OnlyIn(Dist.CLIENT)
public MachineItemGeoRenderer<Ballista> getRenderer() {
return new MachineItemGeoRenderer<>(new MachineItemModel<>("ballista"));
}
});
public static final RegistryObject<Item> BATTERING_RAM = ITEMS.register("battering_ram", () -> new MachineItem<>(new Item.Properties(), EntityTypes.BATTERING_RAM, () -> MachineType.BATTERING_RAM) {
@Override
@OnlyIn(Dist.CLIENT)
public MachineItemGeoRenderer<BatteringRam> getRenderer() {
return new MachineItemGeoRenderer<>(new MachineItemModel<>("battering_ram"));
}
});
public static final RegistryObject<Item> SIEGE_LADDER = ITEMS.register("siege_ladder", () -> new MachineItem<>(new Item.Properties(), EntityTypes.SIEGE_LADDER, () -> MachineType.SIEGE_LADDER) {
@Override
@OnlyIn(Dist.CLIENT)
public MachineItemGeoRenderer<SiegeLadder> getRenderer() {
return new MachineItemGeoRenderer<>(new MachineItemModel<>("siege_ladder"));
}
});
public static final RegistryObject<Item> CANNONBALL = ITEMS.register("cannonball", () -> new Item(new Item.Properties().stacksTo(16).tab(ModItems.GROUP_SM)));
public static final RegistryObject<Item> CANNONBALL = ITEMS.register("cannonball", () -> new Item(new Item.Properties().stacksTo(16)));
public static final RegistryObject<Item> STONE = ITEMS.register("stone", () -> new Item(new Item.Properties().stacksTo(16)));
public static final RegistryObject<Item> GIANT_STONE = ITEMS.register("giant_stone", () -> new Item(new Item.Properties().stacksTo(16)));
public static final RegistryObject<Item> GIANT_ARROW = ITEMS.register("giant_arrow", () -> new Item(new Item.Properties().stacksTo(16).tab(ModItems.GROUP_SM)));
public static final RegistryObject<Item> GIANT_ARROW = ITEMS.register("giant_arrow", () -> new Item(new Item.Properties().stacksTo(16)));
public static final RegistryObject<Item> TURRET_BASE = ITEMS.register("turret_base", () -> new Item(new Item.Properties().tab(ModItems.GROUP_SM)));
public static final RegistryObject<Item> BEAM = ITEMS.register("beam", () -> new Item(new Item.Properties().tab(ModItems.GROUP_SM)));
public static final RegistryObject<Item> COUNTERWEIGHT = ITEMS.register("counterweight", () -> new Item(new Item.Properties().tab(ModItems.GROUP_SM)));
public static final RegistryObject<Item> BARREL = ITEMS.register("barrel", () -> new Item(new Item.Properties().tab(ModItems.GROUP_SM)));
public static final RegistryObject<Item> WHEEL = ITEMS.register("wheel", () -> new Item(new Item.Properties().tab(ModItems.GROUP_SM)));
public static final RegistryObject<Item> TURRET_BASE = ITEMS.register("turret_base", () -> new Item(new Item.Properties()));
public static final RegistryObject<Item> BEAM = ITEMS.register("beam", () -> new Item(new Item.Properties()));
public static final RegistryObject<Item> COUNTERWEIGHT = ITEMS.register("counterweight", () -> new Item(new Item.Properties()));
public static final RegistryObject<Item> BARREL = ITEMS.register("barrel", () -> new Item(new Item.Properties()));
public static final RegistryObject<Item> WHEEL = ITEMS.register("wheel", () -> new Item(new Item.Properties());
public static void register(IEventBus eventBus)
{
public static void register(IEventBus eventBus) {
ITEMS.register(eventBus);
}
}

View File

@@ -3,20 +3,26 @@ package ru.magistu.siegemachines.item.recipes;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gson.*;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import net.minecraft.core.NonNullList;
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.common.crafting.IShapedRecipe;
import org.jetbrains.annotations.NotNull;
import ru.magistu.siegemachines.SiegeMachines;
import net.minecraft.core.NonNullList;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.*;
import net.minecraft.world.level.Level;
import ru.magistu.siegemachines.block.ModBlocks;
import java.util.List;
@@ -24,20 +30,19 @@ import java.util.Map;
import java.util.Set;
public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
{
public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer> {
static ResourceLocation TYPE_ID = new ResourceLocation(SiegeMachines.ID, "siege_workbench");
static int MAX_WIDTH = 3;
static int MAX_HEIGHT = 3;
private final ResourceLocation id;
private final ItemStack result;
private final List<CountIngredient> recipeitems;
final int width;
final int height;
public SiegeWorkbenchRecipe(ResourceLocation id, int width, int height, List<CountIngredient> recipeitems, ItemStack result) {
this.id = id;
this.width = width;
@@ -46,13 +51,11 @@ public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
this.result = result;
}
public static class Type implements RecipeType<SiegeWorkbenchRecipe>
{
public static class Type implements RecipeType<SiegeWorkbenchRecipe> {
public static final Type INSTANCE = new Type();
@Override
public String toString()
{
public String toString() {
return SiegeWorkbenchRecipe.TYPE_ID.toString();
}
}
@@ -69,8 +72,7 @@ public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
@Override
@NotNull
public RecipeType<?> getType()
{
public RecipeType<?> getType() {
return Type.INSTANCE;
}
@@ -84,24 +86,17 @@ public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
public boolean isSpecial() {
return true;
}
/**
* Get the result of this recipe, usually for display purposes (e.g. recipe book). If your recipe has more than one
* possible result (e.g. it's dynamic and depends on its inputs), then return an empty stack.
*/
@Override
public ItemStack getResultItem() {
return this.result;
}
public List<CountIngredient> getRecipeItems()
{
public List<CountIngredient> getRecipeItems() {
return this.recipeitems;
}
@Override
public NonNullList<Ingredient> getIngredients()
{
public NonNullList<Ingredient> getIngredients() {
NonNullList<Ingredient> list = NonNullList.create();
for (CountIngredient ingredient : this.recipeitems)
list.add(ingredient.get());
@@ -114,12 +109,17 @@ public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
public boolean canCraftInDimensions(int width, int height) {
return width >= this.width && height >= this.height;
}
@Override
public ItemStack getResultItem(RegistryAccess registryAccess) {
return null;
}
@NotNull
@Override
public NonNullList<ItemStack> getRemainingItems(CraftingContainer container) {
for(int i = 0; i <= container.getWidth() - this.width; ++i) {
for(int j = 0; j <= container.getHeight() - this.height; ++j) {
for (int i = 0; i <= container.getWidth() - this.width; ++i) {
for (int j = 0; j <= container.getHeight() - this.height; ++j) {
if (this.matches(container, i, j, true)) {
return getRemainingItems(container, i, j, true);
}
@@ -132,13 +132,12 @@ public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
return NonNullList.withSize(container.getContainerSize(), ItemStack.EMPTY);
}
private NonNullList<ItemStack> getRemainingItems(CraftingContainer container, int width, int height, boolean mirrored)
{
private NonNullList<ItemStack> getRemainingItems(CraftingContainer container, int width, int height, boolean mirrored) {
NonNullList<ItemStack> nonnulllist = NonNullList.withSize(container.getContainerSize(), ItemStack.EMPTY);
for(int i = 0; i < container.getWidth(); ++i) {
for(int j = 0; j < container.getHeight(); ++j) {
for (int i = 0; i < container.getWidth(); ++i) {
for (int j = 0; j < container.getHeight(); ++j) {
int k = i - width;
int l = j - height;
CountIngredient ingredient = CountIngredient.of(Ingredient.EMPTY);
@@ -149,7 +148,7 @@ public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
ingredient = this.recipeitems.get(k + l * this.width);
}
}
int index = i + j * container.getWidth();
ItemStack stack = container.getItem(index);
stack.setCount(ingredient.getCount());
@@ -159,13 +158,13 @@ public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
return nonnulllist;
}
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(CraftingContainer container, Level level) {
for(int i = 0; i <= container.getWidth() - this.width; ++i) {
for(int j = 0; j <= container.getHeight() - this.height; ++j) {
for (int i = 0; i <= container.getWidth() - this.width; ++i) {
for (int j = 0; j <= container.getHeight() - this.height; ++j) {
if (this.matches(container, i, j, true)) {
return true;
}
@@ -179,12 +178,17 @@ public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
return false;
}
@Override
public ItemStack assemble(CraftingContainer craftingContainer, RegistryAccess registryAccess) {
return this.getResultItem().copy();
}
/**
* Checks if the region of a crafting inventory is match for the recipe.
*/
private boolean matches(CraftingContainer container, int width, int height, boolean mirrored) {
for(int i = 0; i < container.getWidth(); ++i) {
for(int j = 0; j < container.getHeight(); ++j) {
for (int i = 0; i < container.getWidth(); ++i) {
for (int j = 0; j < container.getHeight(); ++j) {
int k = i - width;
int l = j - height;
CountIngredient ingredient = CountIngredient.of(Ingredient.EMPTY);
@@ -205,13 +209,6 @@ public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
return true;
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack assemble(CraftingContainer container) {
return this.getResultItem().copy();
}
public int getWidth() {
return this.width;
}
@@ -235,12 +232,11 @@ public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
Set<String> set = Sets.newHashSet(keys.keySet());
set.remove(" ");
for(int i = 0; i < pattern.length; ++i) {
for(int j = 0; j < pattern[i].length(); ++j) {
for (int i = 0; i < pattern.length; ++i) {
for (int j = 0; j < pattern[i].length(); ++j) {
String s = pattern[i].substring(j, j + 1);
CountIngredient ingredient = keys.get(s);
if (ingredient == null)
{
if (ingredient == null) {
throw new JsonSyntaxException("Pattern references symbol '" + s + "' but it's not defined in the key");
}
@@ -263,7 +259,7 @@ public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
int k = 0;
int l = 0;
for(int i1 = 0; i1 < toshrink.length; ++i1) {
for (int i1 = 0; i1 < toshrink.length; ++i1) {
String s = toshrink[i1];
i = Math.min(i, firstNonSpace(s));
int j1 = lastNonSpace(s);
@@ -284,7 +280,7 @@ public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
} else {
String[] astring = new String[toshrink.length - l - k];
for(int k1 = 0; k1 < astring.length; ++k1) {
for (int k1 = 0; k1 < astring.length; ++k1) {
astring[k1] = toshrink[k1 + k].substring(i, j + 1);
}
@@ -301,7 +297,7 @@ public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
private static int firstNonSpace(String entry) {
int i;
for(i = 0; i < entry.length() && entry.charAt(i) == ' '; ++i) {
for (i = 0; i < entry.length() && entry.charAt(i) == ' '; ++i) {
}
return i;
@@ -309,7 +305,8 @@ public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
private static int lastNonSpace(String entry) {
int i;
for(i = entry.length() - 1; i >= 0 && entry.charAt(i) == ' '; --i) {}
for (i = entry.length() - 1; i >= 0 && entry.charAt(i) == ' '; --i) {
}
return i;
}
@@ -321,7 +318,7 @@ public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
} else if (astring.length == 0) {
throw new JsonSyntaxException("Invalid pattern: empty pattern not allowed");
} else {
for(int i = 0; i < astring.length; ++i) {
for (int i = 0; i < astring.length; ++i) {
String s = GsonHelper.convertToString(patternarray.get(i), "pattern[" + i + "]");
if (s.length() > MAX_WIDTH) {
throw new JsonSyntaxException("Invalid pattern: too many columns, " + MAX_WIDTH + " is maximum");
@@ -344,7 +341,7 @@ public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
static Map<String, CountIngredient> keyFromJson(JsonObject keyentry) {
Map<String, CountIngredient> map = Maps.newHashMap();
for(Map.Entry<String, JsonElement> entry : keyentry.entrySet()) {
for (Map.Entry<String, JsonElement> entry : keyentry.entrySet()) {
if (entry.getKey().length() != 1) {
throw new JsonSyntaxException("Invalid key entry: '" + entry.getKey() + "' is an invalid symbol (must be 1 character only).");
}
@@ -352,7 +349,7 @@ public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
if (" ".equals(entry.getKey())) {
throw new JsonSyntaxException("Invalid key entry: ' ' is a reserved symbol.");
}
map.put(entry.getKey(), CountIngredient.fromJson(entry.getValue().getAsJsonObject()));
}
@@ -360,38 +357,35 @@ public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
return map;
}
public static ItemStack itemStackFromJson(JsonObject stackobject)
{
public static ItemStack itemStackFromJson(JsonObject stackobject) {
return CraftingHelper.getItemStack(stackobject, true, true);
}
public static class Serializer implements RecipeSerializer<SiegeWorkbenchRecipe>
{
public static class Serializer implements RecipeSerializer<SiegeWorkbenchRecipe> {
public static final Serializer INSTANCE = new Serializer();
public static final ResourceLocation ID = new ResourceLocation(SiegeMachines.ID,"siege_workbench");
public static final ResourceLocation ID = new ResourceLocation(SiegeMachines.ID, "siege_workbench");
@Override
public SiegeWorkbenchRecipe fromJson(ResourceLocation recipeid, JsonObject json)
{
public SiegeWorkbenchRecipe fromJson(ResourceLocation recipeid, JsonObject json) {
Map<String, CountIngredient> map = SiegeWorkbenchRecipe.keyFromJson(GsonHelper.getAsJsonObject(json, "key"));
String[] astring = SiegeWorkbenchRecipe.shrink(SiegeWorkbenchRecipe.patternFromJson(GsonHelper.getAsJsonArray(json, "pattern")));
int i = astring[0].length();
int j = astring.length;
List<CountIngredient> list = SiegeWorkbenchRecipe.dissolvePattern(astring, map, i, j);
ItemStack result = SiegeWorkbenchRecipe.itemStackFromJson(GsonHelper.getAsJsonObject(json, "result"));
return new SiegeWorkbenchRecipe(recipeid, i, j, list, result);
}
@Override
public SiegeWorkbenchRecipe fromNetwork(ResourceLocation recipeid, FriendlyByteBuf buffer) {
int i = buffer.readVarInt();
int j = buffer.readVarInt();
NonNullList<CountIngredient> list = NonNullList.withSize(i * j, CountIngredient.of(Ingredient.EMPTY));
for(int k = 0; k < list.size(); ++k) {
for (int k = 0; k < list.size(); ++k) {
list.set(k, CountIngredient.fromNetwork(buffer));
}
@@ -404,32 +398,11 @@ public class SiegeWorkbenchRecipe implements IShapedRecipe<CraftingContainer>
buffer.writeVarInt(pRecipe.width);
buffer.writeVarInt(pRecipe.height);
for(CountIngredient ingredient : pRecipe.recipeitems) {
for (CountIngredient ingredient : pRecipe.recipeitems) {
ingredient.toNetwork(buffer);
}
buffer.writeItem(pRecipe.result);
}
// @Override
// public RecipeSerializer<?> setRegistryName(ResourceLocation name) {
// return INSTANCE;
// }
//
// @Nullable
// @Override
// public ResourceLocation getRegistryName() {
// return ID;
// }
//
// @Override
// public Class<RecipeSerializer<?>> getRegistryType() {
// return Serializer.castClass(RecipeSerializer.class);
// }
//
// @SuppressWarnings("unchecked") // Need this wrapper, because generics
// private static <G> Class<G> castClass(Class<?> cls) {
// return (Class<G>)cls;
// }
}
}

View File

@@ -1,6 +1,5 @@
package ru.magistu.siegemachines.network;
import ru.magistu.siegemachines.SiegeMachines;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
@@ -8,17 +7,16 @@ import net.minecraftforge.network.NetworkDirection;
import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.simple.SimpleChannel;
import net.minecraftforge.server.ServerLifecycleHooks;
import ru.magistu.siegemachines.SiegeMachines;
public class PacketHandler
{
public class PacketHandler {
private static final String PROTOCOL_VERSION = "1";
public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(new ResourceLocation(SiegeMachines.ID, "main"), () -> "1", "1"::equals, "1"::equals);
protected static int currentId = 0;
public static void init()
{
public static void init() {
INSTANCE.registerMessage(getNextId(), PacketMachine.class, PacketMachine::write, PacketMachine::read, PacketMachine.Handler::handle);
INSTANCE.registerMessage(getNextId(), PacketMachineControl.class, PacketMachineControl::write, PacketMachineControl::read, PacketMachineControl.Handler::handle);
INSTANCE.registerMessage(getNextId(), PacketMachineUse.class, PacketMachineUse::write, PacketMachineUse::read, PacketMachineUse.Handler::handle);
@@ -28,8 +26,7 @@ public class PacketHandler
}
public static int getNextId()
{
public static int getNextId() {
int id = currentId;
currentId++;
return id;
@@ -39,27 +36,21 @@ public class PacketHandler
INSTANCE.sendToServer(packet);
}
public static void sendTo(Object packet, ServerPlayer player)
{
public static void sendTo(Object packet, ServerPlayer player) {
if (!(player instanceof net.minecraftforge.common.util.FakePlayer))
INSTANCE.sendTo(packet, player.connection.connection, NetworkDirection.PLAY_TO_CLIENT);
}
public static void sendPacketToAllInArea(Object packet, BlockPos center, int rangesqr)
{
for (ServerPlayer player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers())
{
if (player.distanceToSqr(center.getX(), center.getY(), center.getZ()) < rangesqr)
{
public static void sendPacketToAllInArea(Object packet, BlockPos center, int rangesqr) {
for (ServerPlayer player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers()) {
if (player.distanceToSqr(center.getX(), center.getY(), center.getZ()) < rangesqr) {
sendTo(packet, player);
}
}
}
public static void sendPacketToAll(Object packet)
{
for (ServerPlayer player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers())
{
public static void sendPacketToAll(Object packet) {
for (ServerPlayer player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers()) {
sendTo(packet, player);
}
}

View File

@@ -1,7 +1,6 @@
package ru.magistu.siegemachines.network;
import io.netty.channel.ChannelHandler;
import ru.magistu.siegemachines.entity.machine.Machine;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.FriendlyByteBuf;
@@ -10,72 +9,62 @@ import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.network.NetworkEvent;
import ru.magistu.siegemachines.entity.machine.Machine;
import java.util.function.Supplier;
@ChannelHandler.Sharable
public class PacketMachine
{
private final int entityid;
private final int delayticks;
private final int useticks;
private final float turretyaw;
private final float turretpitch;
public class PacketMachine {
private final int entityid;
private final int delayticks;
private final int useticks;
private final float turretyaw;
private final float turretpitch;
public PacketMachine(int entityid, int delayticks, int useticks, float turretpitch, float turretyaw)
{
this.entityid = entityid;
this.delayticks = delayticks;
this.useticks = useticks;
this.turretpitch = turretpitch;
this.turretyaw = turretyaw;
}
public PacketMachine(int entityid, int delayticks, int useticks, float turretpitch, float turretyaw) {
this.entityid = entityid;
this.delayticks = delayticks;
this.useticks = useticks;
this.turretpitch = turretpitch;
this.turretyaw = turretyaw;
}
public static PacketMachine read(FriendlyByteBuf buf)
{
public static PacketMachine read(FriendlyByteBuf buf) {
return new PacketMachine(buf.readInt(), buf.readInt(), buf.readInt(), buf.readFloat(), buf.readFloat());
}
public static void write(PacketMachine message, FriendlyByteBuf buf)
{
buf.writeInt(message.entityid);
buf.writeInt(message.delayticks);
buf.writeInt(message.useticks);
buf.writeFloat(message.turretpitch);
buf.writeFloat(message.turretyaw);
}
public static void write(PacketMachine message, FriendlyByteBuf buf) {
buf.writeInt(message.entityid);
buf.writeInt(message.delayticks);
buf.writeInt(message.useticks);
buf.writeFloat(message.turretpitch);
buf.writeFloat(message.turretyaw);
}
public static class Handler
{
public static void handle(PacketMachine packet, Supplier<NetworkEvent.Context> ctx)
{
public static class Handler {
public static void handle(PacketMachine packet, Supplier<NetworkEvent.Context> ctx) {
NetworkEvent.Context context = ctx.get();
if (context.getDirection().getReceptionSide() == LogicalSide.CLIENT)
{
if (context.getDirection().getReceptionSide() == LogicalSide.CLIENT) {
context.enqueueWork(() -> PacketMachine.handleClientSide(packet));
}
}
context.setPacketHandled(true);
}
}
@OnlyIn(Dist.CLIENT)
public static void handleClientSide(PacketMachine packet)
{
LocalPlayer player = Minecraft.getInstance().player;
if(packet == null || player == null || player.level == null)
{
return;
}
Entity entity = player.level.getEntity(packet.entityid);
if (!(entity instanceof Machine))
{
@OnlyIn(Dist.CLIENT)
public static void handleClientSide(PacketMachine packet) {
LocalPlayer player = Minecraft.getInstance().player;
if (packet == null || player == null || player.level() == null) {
return;
}
Machine machine = (Machine) entity;
machine.delayticks = packet.delayticks;
machine.useticks = packet.useticks;
machine.setTurretRotations(packet.turretpitch, packet.turretyaw);
}
Entity entity = player.level().getEntity(packet.entityid);
if (!(entity instanceof Machine machine)) {
return;
}
machine.delayticks = packet.delayticks;
machine.useticks = packet.useticks;
machine.setTurretRotations(packet.turretpitch, packet.turretyaw);
}
}

View File

@@ -1,54 +1,47 @@
package ru.magistu.siegemachines.network;
import io.netty.channel.ChannelHandler;
import ru.magistu.siegemachines.entity.machine.Machine;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.network.NetworkEvent;
import ru.magistu.siegemachines.entity.machine.Machine;
import java.util.function.Supplier;
@ChannelHandler.Sharable
public class PacketMachineControl
{
public PacketMachineControl() {}
public class PacketMachineControl {
public PacketMachineControl() {
}
public static PacketMachineControl read(FriendlyByteBuf buf)
{
public static PacketMachineControl read(FriendlyByteBuf buf) {
return new PacketMachineControl();
}
public static void write(PacketMachineControl message, FriendlyByteBuf buf) {}
public static void write(PacketMachineControl message, FriendlyByteBuf buf) {
}
public static class Handler
{
public static void handle(PacketMachineControl packet, Supplier<NetworkEvent.Context> ctx)
{
public static class Handler {
public static void handle(PacketMachineControl packet, Supplier<NetworkEvent.Context> ctx) {
NetworkEvent.Context context = ctx.get();
if (context.getDirection().getReceptionSide() == LogicalSide.SERVER)
{
if (context.getDirection().getReceptionSide() == LogicalSide.SERVER) {
context.enqueueWork(() -> PacketMachineControl.handleServerSide(packet, context.getSender()));
}
}
context.setPacketHandled(true);
}
}
public static void handleServerSide(PacketMachineControl packet, ServerPlayer player)
{
if(packet == null || player == null || !player.isPassenger())
{
return;
}
Entity entity = player.getVehicle();
if (!(entity instanceof Machine))
{
public static void handleServerSide(PacketMachineControl packet, ServerPlayer player) {
if (packet == null || player == null || !player.isPassenger()) {
return;
}
Machine machine = (Machine) entity;
machine.setTurretRotations(player.getXRot(), player.getYRot());
}
Entity entity = player.getVehicle();
if (!(entity instanceof Machine machine)) {
return;
}
machine.setTurretRotations(player.getXRot(), player.getYRot());
}
}

View File

@@ -1,7 +1,6 @@
package ru.magistu.siegemachines.network;
import io.netty.channel.ChannelHandler;
import ru.magistu.siegemachines.entity.machine.Machine;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.FriendlyByteBuf;
@@ -11,42 +10,36 @@ import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.network.NetworkEvent;
import ru.magistu.siegemachines.entity.machine.Machine;
import java.util.function.Supplier;
@ChannelHandler.Sharable
public class PacketMachineInventorySlot
{
public class PacketMachineInventorySlot {
private final int entityid;
private final int slot;
private ItemStack itemstack = ItemStack.EMPTY;
public PacketMachineInventorySlot(int entityid, int slot, ItemStack itemstack)
{
public PacketMachineInventorySlot(int entityid, int slot, ItemStack itemstack) {
this.entityid = entityid;
this.slot = slot;
this.itemstack = itemstack.copy();
}
public static PacketMachineInventorySlot read(FriendlyByteBuf buf)
{
public static PacketMachineInventorySlot read(FriendlyByteBuf buf) {
return new PacketMachineInventorySlot(buf.readInt(), buf.readInt(), buf.readItem());
}
public static void write(PacketMachineInventorySlot message, FriendlyByteBuf buf)
{
public static void write(PacketMachineInventorySlot message, FriendlyByteBuf buf) {
buf.writeInt(message.entityid);
buf.writeInt(message.slot);
buf.writeItemStack(message.itemstack, false);
}
public static class Handler
{
public static void handle(PacketMachineInventorySlot packet, Supplier<NetworkEvent.Context> ctx)
{
public static class Handler {
public static void handle(PacketMachineInventorySlot packet, Supplier<NetworkEvent.Context> ctx) {
NetworkEvent.Context context = ctx.get();
if (context.getDirection().getReceptionSide() == LogicalSide.CLIENT)
{
if (context.getDirection().getReceptionSide() == LogicalSide.CLIENT) {
context.enqueueWork(() -> PacketMachineInventorySlot.handleClientSide(packet));
}
context.setPacketHandled(true);
@@ -54,17 +47,14 @@ public class PacketMachineInventorySlot
}
@OnlyIn(Dist.CLIENT)
public static void handleClientSide(PacketMachineInventorySlot packet)
{
public static void handleClientSide(PacketMachineInventorySlot packet) {
LocalPlayer player = Minecraft.getInstance().player;
if(packet == null || player == null || player.level == null)
{
if (packet == null || player == null || player.level() == null) {
return;
}
Entity entity = player.level.getEntity(packet.entityid);
if (!(entity instanceof Machine))
{
Entity entity = player.level().getEntity(packet.entityid);
if (!(entity instanceof Machine)) {
return;
}
Machine machine = (Machine) entity;

View File

@@ -1,7 +1,6 @@
package ru.magistu.siegemachines.network;
import io.netty.channel.ChannelHandler;
import ru.magistu.siegemachines.entity.machine.Machine;
import net.minecraft.client.Minecraft;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.Entity;
@@ -10,66 +9,53 @@ import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.network.NetworkEvent;
import ru.magistu.siegemachines.entity.machine.Machine;
import java.util.function.Supplier;
@ChannelHandler.Sharable
public class PacketMachineUse
{
private final int entityid;
public class PacketMachineUse {
private final int entityid;
public PacketMachineUse(int entityid)
{
this.entityid = entityid;
}
public PacketMachineUse(int entityid) {
this.entityid = entityid;
}
public static PacketMachineUse read(FriendlyByteBuf buf)
{
public static PacketMachineUse read(FriendlyByteBuf buf) {
return new PacketMachineUse(buf.readInt());
}
public static void write(PacketMachineUse message, FriendlyByteBuf buf)
{
buf.writeInt(message.entityid);
}
public static void write(PacketMachineUse message, FriendlyByteBuf buf) {
buf.writeInt(message.entityid);
}
public static class Handler
{
public static void handle(PacketMachineUse packet, Supplier<NetworkEvent.Context> ctx)
{
public static class Handler {
public static void handle(PacketMachineUse packet, Supplier<NetworkEvent.Context> ctx) {
NetworkEvent.Context context = ctx.get();
if (context.getDirection().getReceptionSide() == LogicalSide.SERVER)
{
if (context.getDirection().getReceptionSide() == LogicalSide.SERVER) {
context.enqueueWork(() -> PacketMachineUse.handleEachSide(packet, context.getSender()));
}
else if (context.getDirection().getReceptionSide() == LogicalSide.CLIENT)
{
} else if (context.getDirection().getReceptionSide() == LogicalSide.CLIENT) {
context.enqueueWork(() -> PacketMachineUse.handleClientSide(packet));
}
}
context.setPacketHandled(true);
}
}
@OnlyIn(Dist.CLIENT)
public static void handleClientSide(PacketMachineUse packet)
{
handleEachSide(packet, Minecraft.getInstance().player);
}
@OnlyIn(Dist.CLIENT)
public static void handleClientSide(PacketMachineUse packet) {
handleEachSide(packet, Minecraft.getInstance().player);
}
public static void handleEachSide(PacketMachineUse packet, Player player)
{
if(packet == null || player == null || player.level == null)
{
return;
}
Entity entity = player.level.getEntity(packet.entityid);
if (!(entity instanceof Machine))
{
public static void handleEachSide(PacketMachineUse packet, Player player) {
if (packet == null || player == null || player.level() == null) {
return;
}
Entity entity = player.level().getEntity(packet.entityid);
if (!(entity instanceof Machine machine)) {
return;
}
Machine machine = (Machine) entity;
machine.use(player);
}
}
}

View File

@@ -1,7 +1,6 @@
package ru.magistu.siegemachines.network;
import io.netty.channel.ChannelHandler;
import ru.magistu.siegemachines.entity.machine.Machine;
import net.minecraft.client.Minecraft;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.Entity;
@@ -10,66 +9,53 @@ import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.network.NetworkEvent;
import ru.magistu.siegemachines.entity.machine.Machine;
import java.util.function.Supplier;
@ChannelHandler.Sharable
public class PacketMachineUseRealise
{
private final int entityid;
public class PacketMachineUseRealise {
private final int entityid;
public PacketMachineUseRealise(int entityid)
{
this.entityid = entityid;
}
public PacketMachineUseRealise(int entityid) {
this.entityid = entityid;
}
public static PacketMachineUseRealise read(FriendlyByteBuf buf)
{
public static PacketMachineUseRealise read(FriendlyByteBuf buf) {
return new PacketMachineUseRealise(buf.readInt());
}
public static void write(PacketMachineUseRealise message, FriendlyByteBuf buf)
{
buf.writeInt(message.entityid);
}
public static void write(PacketMachineUseRealise message, FriendlyByteBuf buf) {
buf.writeInt(message.entityid);
}
public static class Handler
{
public static void handle(PacketMachineUseRealise packet, Supplier<NetworkEvent.Context> ctx)
{
public static class Handler {
public static void handle(PacketMachineUseRealise packet, Supplier<NetworkEvent.Context> ctx) {
NetworkEvent.Context context = ctx.get();
if (context.getDirection().getReceptionSide() == LogicalSide.SERVER)
{
if (context.getDirection().getReceptionSide() == LogicalSide.SERVER) {
context.enqueueWork(() -> PacketMachineUseRealise.handleEachSide(packet, context.getSender()));
}
else if (context.getDirection().getReceptionSide() == LogicalSide.CLIENT)
{
} else if (context.getDirection().getReceptionSide() == LogicalSide.CLIENT) {
context.enqueueWork(() -> PacketMachineUseRealise.handleClientSide(packet));
}
}
context.setPacketHandled(true);
}
}
@OnlyIn(Dist.CLIENT)
public static void handleClientSide(PacketMachineUseRealise packet)
{
handleEachSide(packet, Minecraft.getInstance().player);
}
@OnlyIn(Dist.CLIENT)
public static void handleClientSide(PacketMachineUseRealise packet) {
handleEachSide(packet, Minecraft.getInstance().player);
}
public static void handleEachSide(PacketMachineUseRealise packet, Player player)
{
if(packet == null || player == null || player.level == null)
{
return;
}
Entity entity = player.level.getEntity(packet.entityid);
if (!(entity instanceof Machine))
{
public static void handleEachSide(PacketMachineUseRealise packet, Player player) {
if (packet == null || player == null || player.level() == null) {
return;
}
Entity entity = player.level().getEntity(packet.entityid);
if (!(entity instanceof Machine machine)) {
return;
}
Machine machine = (Machine) entity;
machine.useRealise();
}
}
}

View File

@@ -1,54 +1,47 @@
package ru.magistu.siegemachines.network;
import io.netty.channel.ChannelHandler;
import ru.magistu.siegemachines.entity.machine.Machine;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.network.NetworkEvent;
import ru.magistu.siegemachines.entity.machine.Machine;
import java.util.function.Supplier;
@ChannelHandler.Sharable
public class PacketOpenMachineInventory
{
public PacketOpenMachineInventory() {}
public class PacketOpenMachineInventory {
public PacketOpenMachineInventory() {
}
public static PacketOpenMachineInventory read(FriendlyByteBuf buf)
{
public static PacketOpenMachineInventory read(FriendlyByteBuf buf) {
return new PacketOpenMachineInventory();
}
public static void write(PacketOpenMachineInventory message, FriendlyByteBuf buf) {}
public static void write(PacketOpenMachineInventory message, FriendlyByteBuf buf) {
}
public static class Handler
{
public static void handle(PacketOpenMachineInventory packet, Supplier<NetworkEvent.Context> ctx)
{
public static class Handler {
public static void handle(PacketOpenMachineInventory packet, Supplier<NetworkEvent.Context> ctx) {
NetworkEvent.Context context = ctx.get();
if (context.getDirection().getReceptionSide() == LogicalSide.SERVER)
{
if (context.getDirection().getReceptionSide() == LogicalSide.SERVER) {
context.enqueueWork(() -> PacketOpenMachineInventory.handleServerSide(packet, context.getSender()));
}
}
context.setPacketHandled(true);
}
}
public static void handleServerSide(PacketOpenMachineInventory packet, ServerPlayer player)
{
if(packet == null || player == null || !player.isPassenger())
{
return;
}
Entity entity = player.getVehicle();
if (!(entity instanceof Machine))
{
public static void handleServerSide(PacketOpenMachineInventory packet, ServerPlayer player) {
if (packet == null || player == null || !player.isPassenger()) {
return;
}
Entity entity = player.getVehicle();
if (!(entity instanceof Machine machine)) {
return;
}
Machine machine = (Machine) entity;
machine.openInventoryGui();
}
}
}

View File

@@ -17,21 +17,21 @@ import java.util.Objects;
@JeiPlugin
public class JeiSupport implements IModPlugin {
@Override
public ResourceLocation getPluginUid() {
return new ResourceLocation(SiegeMachines.ID, "jei_plugin");
}
@Override
public ResourceLocation getPluginUid() {
return new ResourceLocation(SiegeMachines.ID, "jei_plugin");
}
@Override
public void registerCategories(IRecipeCategoryRegistration registration) {
registration.addRecipeCategories(new
SiegeWorkbenchRecipeCategory(registration.getJeiHelpers().getGuiHelper()));
}
@Override
public void registerCategories(IRecipeCategoryRegistration registration) {
registration.addRecipeCategories(new
SiegeWorkbenchRecipeCategory(registration.getJeiHelpers().getGuiHelper()));
}
@Override
public void registerRecipes(IRecipeRegistration registration) {
RecipeManager rm = Objects.requireNonNull(Minecraft.getInstance().level).getRecipeManager();
List<SiegeWorkbenchRecipe> recipes = rm.getAllRecipesFor(ModRecipes.SIEGE_WORKBENCH_RECIPE);
registration.addRecipes(new RecipeType<>(SiegeWorkbenchRecipeCategory.UID, SiegeWorkbenchRecipe.class), recipes);
}
@Override
public void registerRecipes(IRecipeRegistration registration) {
RecipeManager rm = Objects.requireNonNull(Minecraft.getInstance().level).getRecipeManager();
List<SiegeWorkbenchRecipe> recipes = rm.getAllRecipesFor(ModRecipes.SIEGE_WORKBENCH_RECIPE);
registration.addRecipes(new RecipeType<>(SiegeWorkbenchRecipeCategory.UID, SiegeWorkbenchRecipe.class), recipes);
}
}

View File

@@ -20,48 +20,46 @@ import javax.annotation.Nonnull;
import java.util.List;
public class SiegeWorkbenchRecipeCategory implements IRecipeCategory<SiegeWorkbenchRecipe> {
public final static ResourceLocation TEXTURE = new ResourceLocation(SiegeMachines.ID, "textures/gui/siege_workbench.png");
public final static ResourceLocation UID = new ResourceLocation(SiegeMachines.ID, "siege_workbench_recipe_category");
public final static RecipeType<SiegeWorkbenchRecipe> RECIPE_TYPE = new RecipeType<>(UID, SiegeWorkbenchRecipe.class);
public final static ResourceLocation TEXTURE = new ResourceLocation(SiegeMachines.ID, "textures/gui/siege_workbench.png");
public final static ResourceLocation UID = new ResourceLocation(SiegeMachines.ID, "siege_workbench_recipe_category");
public final static RecipeType<SiegeWorkbenchRecipe> RECIPE_TYPE = new RecipeType<>(UID, SiegeWorkbenchRecipe.class);
private final IDrawable background;
private final IDrawable icon;
private final IDrawable background;
private final IDrawable icon;
public SiegeWorkbenchRecipeCategory(IGuiHelper helper) {
this.background = helper.createDrawable(TEXTURE, 29, 16, 116, 54);
this.icon = helper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(ModBlocks.SIEGE_WORKBENCH.get()));
}
public SiegeWorkbenchRecipeCategory(IGuiHelper helper) {
this.background = helper.createDrawable(TEXTURE, 29, 16, 116, 54);
this.icon = helper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(ModBlocks.SIEGE_WORKBENCH.get()));
}
@Override
public RecipeType<SiegeWorkbenchRecipe> getRecipeType() {
return RECIPE_TYPE;
}
@Override
public RecipeType<SiegeWorkbenchRecipe> getRecipeType() {
return RECIPE_TYPE;
}
@Override
public Component getTitle() {
return Component.translatable("category." + SiegeMachines.ID + ".siege_workbench_crafting");
}
@Override
public Component getTitle() {
return Component.translatable("category." + SiegeMachines.ID + ".siege_workbench_crafting");
}
@Override
public IDrawable getBackground() {
return this.background;
}
// @Override
// public IDrawable getBackground() {
// return this.background;
// }
@Override
public IDrawable getIcon() {
return this.icon;
}
@Override
public IDrawable getIcon() {
return this.icon;
}
@Override
public void setRecipe(@Nonnull IRecipeLayoutBuilder builder, @Nonnull SiegeWorkbenchRecipe recipe, @Nonnull IFocusGroup focusGroup)
{
builder.addSlot(RecipeIngredientRole.OUTPUT, 94, 18).addItemStack(recipe.getResultItem());
List<CountIngredient> grid = recipe.getRecipeItems();
@Override
public void setRecipe(@Nonnull IRecipeLayoutBuilder builder, @Nonnull SiegeWorkbenchRecipe recipe, @Nonnull IFocusGroup focusGroup) {
builder.addSlot(RecipeIngredientRole.OUTPUT, 94, 18).addItemStack(recipe.getResultItem());
List<CountIngredient> grid = recipe.getRecipeItems();
for (int i = 0; i < recipe.getWidth(); ++i)
{
for (int j = 0; j < recipe.getHeight(); ++j)
builder.addSlot(RecipeIngredientRole.INPUT, i * 18, j * 18).addItemStacks(grid.get(i + j * 3).getCountModifiedItemStacks());
}
}
for (int i = 0; i < recipe.getWidth(); ++i) {
for (int j = 0; j < recipe.getHeight(); ++j)
builder.addSlot(RecipeIngredientRole.INPUT, i * 18, j * 18).addItemStacks(grid.get(i + j * 3).getCountModifiedItemStacks());
}
}
}

View File

@@ -2,13 +2,11 @@ package ru.magistu.siegemachines.proxy;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
public interface IProxy
{
public interface IProxy {
void setup(IEventBus paramIEventBus1, IEventBus paramIEventBus2);
public void clientSetup(FMLClientSetupEvent event);
public void onPreInit();
}

View File

@@ -1,15 +1,16 @@
package ru.magistu.siegemachines.server;
import ru.magistu.siegemachines.proxy.IProxy;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import ru.magistu.siegemachines.proxy.IProxy;
public class ServerProxy implements IProxy
{
public void setup(IEventBus modEventBus, IEventBus forgeEventBus) {}
public class ServerProxy implements IProxy {
public void setup(IEventBus modEventBus, IEventBus forgeEventBus) {
}
public void clientSetup(FMLClientSetupEvent event) {}
public void clientSetup(FMLClientSetupEvent event) {
}
public void onPreInit() {}
public void onPreInit() {
}
}

View File

@@ -2,12 +2,11 @@ package ru.magistu.siegemachines.util;
import net.minecraft.world.phys.Vec3;
public class CartesianGeometry
{
public static Vec3 applyRotations(Vec3 vec, double pitch, double yaw) {
double x = vec.x * Math.cos(yaw) - vec.y * Math.sin(pitch) * Math.sin(yaw) - vec.z * Math.sin(yaw) * Math.cos(pitch);
double y = vec.y * Math.cos(pitch) - vec.z * Math.sin(pitch);
double z = vec.x * Math.sin(yaw) + vec.y * Math.sin(pitch) * Math.cos(yaw) + vec.z * Math.cos(yaw) * Math.cos(pitch);
return new Vec3(x, y, z);
}
public class CartesianGeometry {
public static Vec3 applyRotations(Vec3 vec, double pitch, double yaw) {
double x = vec.x * Math.cos(yaw) - vec.y * Math.sin(pitch) * Math.sin(yaw) - vec.z * Math.sin(yaw) * Math.cos(pitch);
double y = vec.y * Math.cos(pitch) - vec.z * Math.sin(pitch);
double z = vec.x * Math.sin(yaw) + vec.y * Math.sin(pitch) * Math.cos(yaw) + vec.z * Math.cos(yaw) * Math.cos(pitch);
return new Vec3(x, y, z);
}
}