Compare commits

..

No commits in common. "39786b4612f88385ec496e5e6694b9be5149d314" and "257553d3747391895518d91b564a8fb36e41ac0f" have entirely different histories.

26 changed files with 330 additions and 203 deletions

View File

@ -5,7 +5,7 @@ minecraft_version=1.20.1
# The Minecraft version range can use any release version of Minecraft as bounds. # The Minecraft version range can use any release version of Minecraft as bounds.
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly # Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions. # as they do not follow standard versioning conventions.
minecraft_version_range=[1.20.1,1.20.2] minecraft_version_range=[1.20.1]
# The Forge version must agree with the Minecraft version to get a valid artifact # The Forge version must agree with the Minecraft version to get a valid artifact
forge_version=47.3.22 forge_version=47.3.22
# The Forge version range can use any version of Forge as bounds or match the loader version range # The Forge version range can use any version of Forge as bounds or match the loader version range
@ -38,7 +38,7 @@ mod_name=Enhanced Explosives
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=All Rights Reserved mod_license=All Rights Reserved
# The mod version. See https://semver.org/ # The mod version. See https://semver.org/
mod_version=0.13.2 mod_version=0.11.0
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources. # This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html # See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View File

@ -1,11 +1,11 @@
package com.jenny.enhancedexplosives; package com.jenny.enhancedexplosives;
import com.jenny.enhancedexplosives.blocks.blocks; import com.jenny.enhancedexplosives.blocks.blocks;
import com.jenny.enhancedexplosives.config.ConfigCommon;
import com.jenny.enhancedexplosives.particles.particles;
import com.jenny.enhancedexplosives.config.ConfigClient; import com.jenny.enhancedexplosives.config.ConfigClient;
import com.jenny.enhancedexplosives.config.ConfigServer;
import com.jenny.enhancedexplosives.entities.entities; import com.jenny.enhancedexplosives.entities.entities;
import com.jenny.enhancedexplosives.items.items; import com.jenny.enhancedexplosives.items.items;
import com.jenny.enhancedexplosives.particles.particles;
import com.mojang.logging.LogUtils; import com.mojang.logging.LogUtils;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
@ -27,7 +27,6 @@ public class EnhancedExplosives {
public static final String MODID = "enhancedexplosives"; public static final String MODID = "enhancedexplosives";
private static final Logger LOGGER = LogUtils.getLogger(); private static final Logger LOGGER = LogUtils.getLogger();
@SuppressWarnings("removal")
public EnhancedExplosives() { public EnhancedExplosives() {
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
@ -41,12 +40,10 @@ public class EnhancedExplosives {
// Register ourselves for server and other game events we are interested in // Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ConfigClient.SPEC, "enhancedexplosives-client.toml");
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ConfigServer.SPEC, "enhancedexplosives-server.toml");
} }
private void commonSetup(final FMLCommonSetupEvent event) { private void commonSetup(final FMLCommonSetupEvent event) {
items.registerDispenser(); ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ConfigCommon.SPEC);
} }
// You can use SubscribeEvent and let the Event Bus discover methods to call // You can use SubscribeEvent and let the Event Bus discover methods to call
@ -61,6 +58,7 @@ public class EnhancedExplosives {
@SubscribeEvent @SubscribeEvent
public static void onClientSetup(FMLClientSetupEvent event) { public static void onClientSetup(FMLClientSetupEvent event) {
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ConfigClient.SPEC);
entities.registerRenderers(); entities.registerRenderers();
} }
} }

View File

@ -1,7 +1,8 @@
package com.jenny.enhancedexplosives.blocks; package com.jenny.enhancedexplosives.blocks;
import com.jenny.enhancedexplosives.config.ConfigClient;
import com.jenny.enhancedexplosives.entities.tnt.enderPrimedTNT; import com.jenny.enhancedexplosives.entities.tnt.enderPrimedTNT;
import com.jenny.enhancedexplosives.config.ConfigClient;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.particles.ParticleTypes;
@ -14,6 +15,7 @@ import net.minecraft.world.level.block.TntBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.level.levelgen.Heightmap; import net.minecraft.world.level.levelgen.Heightmap;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -93,7 +95,7 @@ public class enderTNTBlock extends TntBlock {
} }
public static void spawnParticles(Level level, BlockPos blockPos) { public static void spawnParticles(Level level, BlockPos blockPos) {
if (ConfigClient.tntParticles.get()) { if (ConfigClient.tntParticles) {
for (int i = 1; i <= ConfigClient.calcPCount(30); i++) { for (int i = 1; i <= ConfigClient.calcPCount(30); i++) {
float x = blockPos.getX() + (float) level.getRandom().nextIntBetweenInclusive(-10, 10) / 10 + 0.5F; float x = blockPos.getX() + (float) level.getRandom().nextIntBetweenInclusive(-10, 10) / 10 + 0.5F;
float y = blockPos.getY() + (float) level.getRandom().nextIntBetweenInclusive(-10, 10) / 10; float y = blockPos.getY() + (float) level.getRandom().nextIntBetweenInclusive(-10, 10) / 10;

View File

@ -1,5 +1,6 @@
package com.jenny.enhancedexplosives.blocks; package com.jenny.enhancedexplosives.blocks;
import com.jenny.enhancedexplosives.entities.tnt.blackHolePrimedTNT;
import com.jenny.enhancedexplosives.entities.tnt.repulsivePrimedTNT; import com.jenny.enhancedexplosives.entities.tnt.repulsivePrimedTNT;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;

View File

@ -1,37 +1,42 @@
package com.jenny.enhancedexplosives.config; package com.jenny.enhancedexplosives.config;
import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.config.ModConfigEvent;
import static com.jenny.enhancedexplosives.EnhancedExplosives.MODID; import static com.jenny.enhancedexplosives.EnhancedExplosives.MODID;
@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD) @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ConfigClient { public class ConfigClient {
private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder(); private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
public static final ForgeConfigSpec SPEC;
public static final ForgeConfigSpec.ConfigValue<Boolean> arrowParticles; private static final ForgeConfigSpec.ConfigValue<Boolean> C_ARROW_PARTICLES =
public static final ForgeConfigSpec.ConfigValue<Boolean> tntParticles; BUILDER.comment("whether to spawn client-side particles for arrows")
private static final ForgeConfigSpec.ConfigValue<Double> particlePercent; .define("arrowParticles", true);
static { private static final ForgeConfigSpec.ConfigValue<Boolean> C_TNT_PARTICLES =
BUILDER.comment("weather to spawn client-side particles for tnt")
.define("tntParticles", true);
private static final ForgeConfigSpec.ConfigValue<Double> C_PARTICLE_PERCENT =
BUILDER.comment("amount of particles to spawn (0.0 = None, 1.0 = normal, values higher are valid too)")
.define("arrowParticleCount", 1.0D);
arrowParticles = public static final ForgeConfigSpec SPEC = BUILDER.build();
BUILDER.comment("particles from arrows arrows")
.define("arrow_particles", true);
tntParticles =
BUILDER.comment("particles from tnt")
.define("tnt_particles", true);
particlePercent =
BUILDER.comment("amount of spawned particles (0.0 = None, 1.0 = normal, values higher are valid too)")
.define("particle_amount", 1.0D);
SPEC = BUILDER.build(); public static boolean arrowParticles, tntParticles;
public static float particlePercent;
@SubscribeEvent
static void onLoad(final ModConfigEvent event)
{
arrowParticles = C_ARROW_PARTICLES.get();
tntParticles = C_TNT_PARTICLES.get();
particlePercent = C_PARTICLE_PERCENT.get().floatValue();
} }
public static int calcPCount(int pCount) { public static int calcPCount(int pCount) {
return (int) Math.round(pCount * particlePercent.get()); return Math.round(pCount * particlePercent);
} }
} }

View File

@ -0,0 +1,21 @@
package com.jenny.enhancedexplosives.config;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.config.ModConfigEvent;
import static com.jenny.enhancedexplosives.EnhancedExplosives.MODID;
@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ConfigCommon {
private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
public static final ForgeConfigSpec SPEC = BUILDER.build();
@SubscribeEvent
static void onLoad(final ModConfigEvent event)
{
}
}

View File

@ -1,28 +0,0 @@
package com.jenny.enhancedexplosives.config;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.fml.common.Mod;
import static com.jenny.enhancedexplosives.EnhancedExplosives.MODID;
@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ConfigServer {
private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
public static final ForgeConfigSpec SPEC;
public static final ForgeConfigSpec.ConfigValue<Boolean> claymoreInstantDespawn;
public static final ForgeConfigSpec.ConfigValue<Boolean> homingAtPlayers;
public static final ForgeConfigSpec.ConfigValue<Boolean> carpetCompactDetonation;
static {
claymoreInstantDespawn = BUILDER.comment("Claymore arrows despawn instantly upon hitting a surface")
.define("claymore_instant_arrow_despawn", false);
homingAtPlayers = BUILDER.comment("Homing TNTs are allowed to follow players")
.define("homing_tnt_target_players", true);
carpetCompactDetonation = BUILDER.comment("Carpet Arrow TNTs explode upon explosion damage; This reduces spread")
.define("carpet_arrow_compact_detonation", true);
SPEC = BUILDER.build();
}
}

View File

@ -19,7 +19,7 @@ import static com.jenny.enhancedexplosives.EnhancedExplosives.MODID;
public class creativeTab { public class creativeTab {
public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID); public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID);
public static final RegistryObject<CreativeModeTab> CREATIVE_TAB = CREATIVE_MODE_TABS.register("enhancedexplosives", () -> CreativeModeTab.builder().withTabsBefore(CreativeModeTabs.SPAWN_EGGS).icon(() -> blocks.TNT_8_ITEM.get().getDefaultInstance()).displayItems((parameters, output) -> { public static final RegistryObject<CreativeModeTab> CREATIVE_TAB = CREATIVE_MODE_TABS.register("enhancedexplosives", () -> CreativeModeTab.builder().withTabsBefore(CreativeModeTabs.COMBAT).icon(() -> blocks.TNT_8_ITEM.get().getDefaultInstance()).displayItems((parameters, output) -> {
output.acceptAll(Arrays.stream(getBlocks()).toList()); output.acceptAll(Arrays.stream(getBlocks()).toList());
output.acceptAll(Arrays.stream(getItems()).toList()); output.acceptAll(Arrays.stream(getItems()).toList());
}).title(Component.literal("Enhanced Explosives")).build()); }).title(Component.literal("Enhanced Explosives")).build());

View File

@ -1,19 +1,16 @@
package com.jenny.enhancedexplosives.datagen; package com.jenny.enhancedexplosives.datagen;
import com.jenny.enhancedexplosives.blocks.blocks; import com.jenny.enhancedexplosives.blocks.blocks;
import net.minecraft.data.PackOutput; import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.client.model.generators.BlockStateProvider; import net.minecraftforge.client.model.generators.BlockStateProvider;
import net.minecraftforge.client.model.generators.ConfiguredModel; import net.minecraftforge.client.model.generators.ConfiguredModel;
import net.minecraftforge.client.model.generators.ModelFile;
import net.minecraftforge.common.data.ExistingFileHelper; import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject; import net.minecraftforge.registries.RegistryObject;
import org.jetbrains.annotations.NotNull; import net.minecraftforge.client.model.generators.ModelFile;
import java.util.Objects;
import static com.jenny.enhancedexplosives.EnhancedExplosives.MODID; import static com.jenny.enhancedexplosives.EnhancedExplosives.MODID;
@ -40,20 +37,20 @@ public class ModBlockStateProvider extends BlockStateProvider {
SideOnlyTNT(blocks.TNT_HOMING); SideOnlyTNT(blocks.TNT_HOMING);
} }
private void blockWithItem(@NotNull RegistryObject<Block> blockRegistryObject) { private void blockWithItem(RegistryObject<Block> blockRegistryObject) {
simpleBlockWithItem(blockRegistryObject.get(), cubeAll(blockRegistryObject.get())); simpleBlockWithItem(blockRegistryObject.get(), cubeAll(blockRegistryObject.get()));
} }
private void SideTop(@NotNull RegistryObject<Block> blockRegistryObject) { private void SideTop(RegistryObject<Block> blockRegistryObject) {
simpleBlockWithItem(blockRegistryObject.get(), topSide(blockRegistryObject.get())); simpleBlockWithItem(blockRegistryObject.get(), topSide(blockRegistryObject.get()));
} }
private void blockItem(@NotNull RegistryObject<Block> blockRegistryObject) { private void blockItem(RegistryObject<Block> blockRegistryObject) {
simpleBlockItem(blockRegistryObject.get(), new ModelFile.UncheckedModelFile(MODID + simpleBlockItem(blockRegistryObject.get(), new ModelFile.UncheckedModelFile(MODID +
":block/" + Objects.requireNonNull(ForgeRegistries.BLOCKS.getKey(blockRegistryObject.get())).getPath())); ":block/" + ForgeRegistries.BLOCKS.getKey(blockRegistryObject.get()).getPath()));
} }
private void topBottom2Sides(@NotNull RegistryObject<Block> blockRegistryObject) { private void topBottom2Sides(RegistryObject<Block> blockRegistryObject) {
simpleBlockWithItem(blockRegistryObject.get(), northEastTopBottom(blockRegistryObject.get())); simpleBlockWithItem(blockRegistryObject.get(), northEastTopBottom(blockRegistryObject.get()));
} }
@ -61,22 +58,22 @@ public class ModBlockStateProvider extends BlockStateProvider {
return ForgeRegistries.BLOCKS.getKey(block); return ForgeRegistries.BLOCKS.getKey(block);
} }
private @NotNull String name(Block block) { private String name(Block block) {
return key(block).getPath(); return key(block).getPath();
} }
private ResourceLocation extend(@NotNull ResourceLocation rl, String suffix) { private ResourceLocation extend(ResourceLocation rl, String suffix) {
return new ResourceLocation(rl.getNamespace(), rl.getPath() + suffix); return new ResourceLocation(rl.getNamespace(), rl.getPath() + suffix);
} }
public void sideTopBottom(@NotNull RegistryObject<Block> blockRegistryObject) { public void sideTopBottom(RegistryObject<Block> blockRegistryObject) {
Block block = blockRegistryObject.get(); Block block = blockRegistryObject.get();
ModelFile model = models().cubeBottomTop(name(block), extend(blockTexture(block), "_side"), extend(blockTexture(block), "_bottom"), extend(blockTexture(block), "_top")); ModelFile model = models().cubeBottomTop(name(block), extend(blockTexture(block), "_side"), extend(blockTexture(block), "_bottom"), extend(blockTexture(block), "_top"));
this.getVariantBuilder(block).forAllStates(blockState -> ConfiguredModel.builder().modelFile(model).build()); this.getVariantBuilder(block).forAllStates(blockState -> ConfiguredModel.builder().modelFile(model).build());
simpleBlockItem(block, model); simpleBlockItem(block, model);
} }
public void SideOnlyTNT(@NotNull RegistryObject<Block> blockRegistryObject) { public void SideOnlyTNT(RegistryObject<Block> blockRegistryObject) {
Block block = blockRegistryObject.get(); Block block = blockRegistryObject.get();
ModelFile model = models().cubeBottomTop(name(block), extend(blockTexture(block), "_side"), extend(blockTexture(Blocks.TNT), "_bottom"), extend(blockTexture(Blocks.TNT), "_top")); ModelFile model = models().cubeBottomTop(name(block), extend(blockTexture(block), "_side"), extend(blockTexture(Blocks.TNT), "_bottom"), extend(blockTexture(Blocks.TNT), "_top"));
this.getVariantBuilder(block).forAllStates(blockState -> ConfiguredModel.builder().modelFile(model).build()); this.getVariantBuilder(block).forAllStates(blockState -> ConfiguredModel.builder().modelFile(model).build());

View File

@ -1,9 +1,11 @@
package com.jenny.enhancedexplosives.datagen; package com.jenny.enhancedexplosives.datagen;
import com.jenny.enhancedexplosives.items.items; import com.jenny.enhancedexplosives.items.items;
import net.minecraft.data.PackOutput; import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraftforge.client.model.generators.ItemModelBuilder;
import net.minecraftforge.client.model.generators.ItemModelProvider; import net.minecraftforge.client.model.generators.ItemModelProvider;
import net.minecraftforge.common.data.ExistingFileHelper; import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.registries.RegistryObject; import net.minecraftforge.registries.RegistryObject;
@ -23,8 +25,8 @@ public class ModItemModelProvider extends ItemModelProvider {
simpleItem(items.TUNNEL_ARROW); simpleItem(items.TUNNEL_ARROW);
} }
private void simpleItem(RegistryObject<Item> item) { private ItemModelBuilder simpleItem(RegistryObject<Item> item) {
withExistingParent(item.getId().getPath(), return withExistingParent(item.getId().getPath(),
new ResourceLocation("item/generated")).texture("layer0", new ResourceLocation("item/generated")).texture("layer0",
new ResourceLocation(MODID,"item/" + item.getId().getPath())); new ResourceLocation(MODID,"item/" + item.getId().getPath()));
} }

View File

@ -1,55 +1,237 @@
package com.jenny.enhancedexplosives.entities.arrows; package com.jenny.enhancedexplosives.entities.arrows;
import com.jenny.enhancedexplosives.config.ConfigClient; import com.google.common.collect.Sets;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.AbstractArrow; import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.entity.projectile.Arrow;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items; import net.minecraft.world.item.Items;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionUtils;
import net.minecraft.world.item.alchemy.Potions;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Set;
public class baseArrow extends AbstractArrow { public class baseArrow extends AbstractArrow {
private static final int EXPOSED_POTION_DECAY_TIME = 600;
private static final int NO_EFFECT_COLOR = -1;
private static final EntityDataAccessor<Integer> ID_EFFECT_COLOR = SynchedEntityData.defineId(Arrow.class, EntityDataSerializers.INT);
private static final byte EVENT_POTION_PUFF = 0;
private Potion potion = Potions.EMPTY;
private final Set<MobEffectInstance> effects = Sets.newHashSet();
private boolean fixedColor;
private int tick = 0; private int tick = 0;
public baseArrow(EntityType<? extends baseArrow> pEntityType, Level pLevel) { public baseArrow(EntityType<? extends baseArrow> pEntityType, Level pLevel) {
super(pEntityType, pLevel); super(pEntityType, pLevel);
} }
public baseArrow(Level pLevel, double pX, double pY, double pZ, EntityType<? extends baseArrow> pEntityType) {
super(pEntityType, pX, pY, pZ, pLevel);
}
public baseArrow(Level pLevel, LivingEntity pShooter, EntityType<? extends baseArrow> pEntityType) { public baseArrow(Level pLevel, LivingEntity pShooter, EntityType<? extends baseArrow> pEntityType) {
super(pEntityType, pShooter, pLevel); super(pEntityType, pShooter, pLevel);
} }
public baseArrow(Level pLevel, EntityType<? extends baseArrow> pEntityType) { public void setEffectsFromItem(ItemStack pStack) {
super(pEntityType, pLevel); if (pStack.is(Items.TIPPED_ARROW)) {
this.potion = PotionUtils.getPotion(pStack);
Collection<MobEffectInstance> collection = PotionUtils.getCustomEffects(pStack);
if (!collection.isEmpty()) {
for(MobEffectInstance mobeffectinstance : collection) {
this.effects.add(new MobEffectInstance(mobeffectinstance));
}
}
int i = getCustomColor(pStack);
if (i == -1) {
this.updateColor();
} else {
this.setFixedColor(i);
}
} else if (pStack.is(Items.ARROW)) {
this.potion = Potions.EMPTY;
this.effects.clear();
this.entityData.set(ID_EFFECT_COLOR, -1);
}
}
public static int getCustomColor(ItemStack pStack) {
CompoundTag compoundtag = pStack.getTag();
return compoundtag != null && compoundtag.contains("CustomPotionColor", 99) ? compoundtag.getInt("CustomPotionColor") : -1;
}
private void updateColor() {
this.fixedColor = false;
if (this.potion == Potions.EMPTY && this.effects.isEmpty()) {
this.entityData.set(ID_EFFECT_COLOR, -1);
} else {
this.entityData.set(ID_EFFECT_COLOR, PotionUtils.getColor(PotionUtils.getAllEffects(this.potion, this.effects)));
}
}
public void addEffect(MobEffectInstance pEffectInstance) {
this.effects.add(pEffectInstance);
this.getEntityData().set(ID_EFFECT_COLOR, PotionUtils.getColor(PotionUtils.getAllEffects(this.potion, this.effects)));
}
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(ID_EFFECT_COLOR, -1);
} }
public void tick() { public void tick() {
super.tick(); super.tick();
if (this.level().isClientSide) { if (this.level().isClientSide) {
if (!this.inGround && ConfigClient.arrowParticles.get()) { if (this.inGround) {
if (this.inGroundTime % 5 == 0) {
this.makeParticle(1);
}
} else {
spawnParticles(0); spawnParticles(0);
} }
this.tick++; this.tick++;
} else if (this.inGround && this.inGroundTime != 0 && !this.effects.isEmpty() && this.inGroundTime >= 600) {
this.level().broadcastEntityEvent(this, (byte)0);
this.potion = Potions.EMPTY;
this.effects.clear();
this.entityData.set(ID_EFFECT_COLOR, -1);
} }
} }
private void makeParticle(int pParticleAmount) {
int i = this.getColor();
if (i != -1 && pParticleAmount > 0) {
double d0 = (double)(i >> 16 & 255) / 255.0D;
double d1 = (double)(i >> 8 & 255) / 255.0D;
double d2 = (double)(i >> 0 & 255) / 255.0D;
for(int j = 0; j < pParticleAmount; ++j) {
this.level().addParticle(ParticleTypes.ENTITY_EFFECT, this.getRandomX(0.5D), this.getRandomY(), this.getRandomZ(0.5D), d0, d1, d2);
}
}
}
public int getColor() {
return this.entityData.get(ID_EFFECT_COLOR);
}
private void setFixedColor(int pFixedColor) {
this.fixedColor = true;
this.entityData.set(ID_EFFECT_COLOR, pFixedColor);
}
public void addAdditionalSaveData(@NotNull CompoundTag pCompound) {
super.addAdditionalSaveData(pCompound);
if (this.potion != Potions.EMPTY) {
pCompound.putString("Potion", BuiltInRegistries.POTION.getKey(this.potion).toString());
}
if (this.fixedColor) {
pCompound.putInt("Color", this.getColor());
}
if (!this.effects.isEmpty()) {
ListTag listtag = new ListTag();
for(MobEffectInstance mobeffectinstance : this.effects) {
listtag.add(mobeffectinstance.save(new CompoundTag()));
}
pCompound.put("CustomPotionEffects", listtag);
}
}
public void readAdditionalSaveData(@NotNull CompoundTag pCompound) {
super.readAdditionalSaveData(pCompound);
if (pCompound.contains("Potion", 8)) {
this.potion = PotionUtils.getPotion(pCompound);
}
for(MobEffectInstance mobeffectinstance : PotionUtils.getCustomEffects(pCompound)) {
this.addEffect(mobeffectinstance);
}
if (pCompound.contains("Color", 99)) {
this.setFixedColor(pCompound.getInt("Color"));
} else {
this.updateColor();
}
}
protected void doPostHurtEffects(@NotNull LivingEntity pLiving) {
super.doPostHurtEffects(pLiving);
Entity entity = this.getEffectSource();
for(MobEffectInstance mobeffectinstance : this.potion.getEffects()) {
pLiving.addEffect(new MobEffectInstance(mobeffectinstance.getEffect(), Math.max(mobeffectinstance.mapDuration((p_268168_) -> {
return p_268168_ / 8;
}), 1), mobeffectinstance.getAmplifier(), mobeffectinstance.isAmbient(), mobeffectinstance.isVisible()), entity);
}
if (!this.effects.isEmpty()) {
for(MobEffectInstance mobeffectinstance1 : this.effects) {
pLiving.addEffect(mobeffectinstance1, entity);
}
}
}
@NotNull @NotNull
protected ItemStack getPickupItem() { protected ItemStack getPickupItem() {
return new ItemStack(Items.ARROW); if (this.effects.isEmpty() && this.potion == Potions.EMPTY) {
return new ItemStack(Items.ARROW);
} else {
ItemStack itemstack = new ItemStack(Items.TIPPED_ARROW);
PotionUtils.setPotion(itemstack, this.potion);
PotionUtils.setCustomEffects(itemstack, this.effects);
if (this.fixedColor) {
itemstack.getOrCreateTag().putInt("CustomPotionColor", this.getColor());
}
return itemstack;
}
} }
protected Vec3 particlePos(double dist) { public void handleEntityEvent(byte pId) {
Double speed = getDeltaMovement().length(); if (pId == 0) {
return new Vec3( int i = this.getColor();
level().getRandom().nextIntBetweenInclusive(-100, 100), if (i != -1) {
level().getRandom().nextIntBetweenInclusive(-100, 100), double d0 = (double)(i >> 16 & 255) / 255.0D;
level().getRandom().nextIntBetweenInclusive(-100, 100) double d1 = (double)(i >> 8 & 255) / 255.0D;
).normalize().scale(dist + ((double) level().getRandom().nextIntBetweenInclusive(0, 100) / 100)).add(position()); double d2 = (double)(i >> 0 & 255) / 255.0D;
for(int j = 0; j < 20; ++j) {
this.level().addParticle(ParticleTypes.ENTITY_EFFECT, this.getRandomX(0.5D), this.getRandomY(), this.getRandomZ(0.5D), d0, d1, d2);
}
}
} else {
super.handleEntityEvent(pId);
}
} }
public void spawnParticles(float partialTicks) { public void spawnParticles(float partialTicks) {
} }
public int getTick() { public int getTick() {

View File

@ -54,10 +54,14 @@ public class carpetArrow extends baseArrow {
@Override @Override
public void spawnParticles(float partialTicks) { public void spawnParticles(float partialTicks) {
for (int i = 1; i <= ConfigClient.calcPCount(5); i++) { for (int i = 1; i <= ConfigClient.calcPCount(3); i++) {
double m = (double) level().getRandom().nextIntBetweenInclusive(-100, 100) / 100; double m = (double) level().getRandom().nextIntBetweenInclusive(-100, 100) / 100;
Vec3 DeltaMovement = getDeltaMovement(); Vec3 DeltaMovement = getDeltaMovement();
Vec3 pos = particlePos(0.5); Vec3 pos = new Vec3(
(double) level().getRandom().nextIntBetweenInclusive(-5, 5) / 10,
0,
(double) level().getRandom().nextIntBetweenInclusive(-5, 5) / 10
).normalize().multiply(m, 0, m).add(getPosition(partialTicks));
level().addParticle(particles.CARPET_ARROW_PARTICLE.get(), pos.x, pos.y, pos.z, DeltaMovement.x, DeltaMovement.y, DeltaMovement.z); level().addParticle(particles.CARPET_ARROW_PARTICLE.get(), pos.x, pos.y, pos.z, DeltaMovement.x, DeltaMovement.y, DeltaMovement.z);
} }
} }

View File

@ -1,11 +1,11 @@
package com.jenny.enhancedexplosives.entities.arrows; package com.jenny.enhancedexplosives.entities.arrows;
import com.jenny.enhancedexplosives.config.ConfigClient; import com.jenny.enhancedexplosives.config.ConfigClient;
import com.jenny.enhancedexplosives.config.ConfigServer;
import com.jenny.enhancedexplosives.entities.entities; import com.jenny.enhancedexplosives.entities.entities;
import com.jenny.enhancedexplosives.items.items; import com.jenny.enhancedexplosives.items.items;
import com.jenny.enhancedexplosives.particles.particles; import com.jenny.enhancedexplosives.particles.particles;
import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageType;
import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
@ -20,13 +20,13 @@ public class carpetArrowPart extends baseArrow {
} }
public carpetArrowPart(Level pLevel, LivingEntity pShooter) { public carpetArrowPart(Level pLevel, LivingEntity pShooter) {
super(pLevel, entities.ARROW_CARPET_PART.get()); super(pLevel, pShooter, entities.ARROW_CARPET_PART.get());
} }
@Override @Override
public void tick() { public void tick() {
super.tick(); super.tick();
if (this.inGround || (this.hurtMarked && !this.level().isClientSide && ConfigServer.carpetCompactDetonation.get())) { if (this.inGround || this.hurtMarked) {
explode(); explode();
} }
} }

View File

@ -1,20 +1,17 @@
package com.jenny.enhancedexplosives.entities.arrows; package com.jenny.enhancedexplosives.entities.arrows;
import com.jenny.enhancedexplosives.config.ConfigServer;
import com.jenny.enhancedexplosives.entities.entities; import com.jenny.enhancedexplosives.entities.entities;
import com.jenny.enhancedexplosives.items.items; import com.jenny.enhancedexplosives.items.items;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class claymoreArrow extends baseArrow{ public class claymoreArrow extends baseArrow{
private final int r = level().isClientSide ? 0 : (ConfigServer.claymoreInstantDespawn.get() ? -20 : level().getRandom().nextInt(0, 20));
public claymoreArrow(EntityType<claymoreArrow> pEntityType, Level pLevel) { public claymoreArrow(EntityType<claymoreArrow> pEntityType, Level pLevel) {
super(pEntityType, pLevel); super(pEntityType, pLevel);
} }
public claymoreArrow(@NotNull Level pLevel, @NotNull LivingEntity pShooter) { public claymoreArrow(@NotNull Level pLevel, @NotNull LivingEntity pShooter) {
@ -26,14 +23,6 @@ public class claymoreArrow extends baseArrow{
pTarget.hurt(damageSources().mobProjectile(this, (LivingEntity) getOwner()), 15); pTarget.hurt(damageSources().mobProjectile(this, (LivingEntity) getOwner()), 15);
} }
@Override
public void tick() {
super.tick();
if (!level().isClientSide && this.inGroundTime > 20 + r) {
discard();
}
}
@Override @Override
@NotNull @NotNull
protected ItemStack getPickupItem() { protected ItemStack getPickupItem() {

View File

@ -1,9 +1,10 @@
package com.jenny.enhancedexplosives.entities.arrows; package com.jenny.enhancedexplosives.entities.arrows;
import com.jenny.enhancedexplosives.config.ConfigClient;
import com.jenny.enhancedexplosives.entities.entities; import com.jenny.enhancedexplosives.entities.entities;
import com.jenny.enhancedexplosives.items.items; import com.jenny.enhancedexplosives.items.items;
import com.jenny.enhancedexplosives.config.ConfigClient;
import com.jenny.enhancedexplosives.particles.particles; import com.jenny.enhancedexplosives.particles.particles;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -42,10 +43,15 @@ public class concussiveArrow extends baseArrow{
@Override @Override
public void spawnParticles(float partialTicks) { public void spawnParticles(float partialTicks) {
for (int i = 1; i <= ConfigClient.calcPCount(5); i++) { for (int i = 1; i <= ConfigClient.calcPCount(3); i++) {
Vec3 delta = getDeltaMovement(); double m = (double) level().getRandom().nextIntBetweenInclusive(- 100, 100) / 100;
Vec3 pos = particlePos(0.5); Vec3 DeltaMovement = getDeltaMovement();
level().addParticle(particles.CONCUSSIVE_ARROW_PARTICLE.get(), pos.x, pos.y, pos.z, delta.x, delta.y, delta.z); Vec3 pos = new Vec3(
(double) level().getRandom().nextIntBetweenInclusive(-5, 5) / 10,
0,
(double) level().getRandom().nextIntBetweenInclusive(-5, 5) / 10
).normalize().multiply(m, m, m).add(getPosition(partialTicks));
level().addParticle(particles.CONCUSSIVE_ARROW_PARTICLE.get(), pos.x, pos.y, pos.z, DeltaMovement.x, DeltaMovement.y, DeltaMovement.z);
} }
} }
} }

View File

@ -1,8 +1,9 @@
package com.jenny.enhancedexplosives.entities.arrows; package com.jenny.enhancedexplosives.entities.arrows;
import com.jenny.enhancedexplosives.config.ConfigClient; import com.jenny.enhancedexplosives.config.ConfigClient;
import com.jenny.enhancedexplosives.entities.entities;
import com.jenny.enhancedexplosives.items.items; import com.jenny.enhancedexplosives.items.items;
import com.jenny.enhancedexplosives.entities.entities;
import com.jenny.enhancedexplosives.particles.particles; import com.jenny.enhancedexplosives.particles.particles;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
@ -42,10 +43,14 @@ public class tntArrow extends baseArrow {
@Override @Override
public void spawnParticles(float partialTicks) { public void spawnParticles(float partialTicks) {
for (int i = 1; i <= ConfigClient.calcPCount(5); i++) { for (int i = 1; i <= ConfigClient.calcPCount(3); i++) {
double m = (double) level().getRandom().nextIntBetweenInclusive(- 100, 100) / 100; double m = (double) level().getRandom().nextIntBetweenInclusive(- 100, 100) / 100;
Vec3 DeltaMovement = getDeltaMovement(); Vec3 DeltaMovement = getDeltaMovement();
Vec3 pos = particlePos(0.5); Vec3 pos = new Vec3(
(double) level().getRandom().nextIntBetweenInclusive(-5, 5) / 10,
0,
(double) level().getRandom().nextIntBetweenInclusive(-5, 5) / 10
).normalize().multiply(m, m, m).add(getPosition(partialTicks));
level().addParticle(particles.TNT_ARROW_PARTICLE.get(), pos.x, pos.y, pos.z, DeltaMovement.x, DeltaMovement.y, DeltaMovement.z); level().addParticle(particles.TNT_ARROW_PARTICLE.get(), pos.x, pos.y, pos.z, DeltaMovement.x, DeltaMovement.y, DeltaMovement.z);
} }
} }

View File

@ -11,9 +11,9 @@ import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class tunnelArrow extends baseArrow{ public class tunnelArrow extends baseArrow{
protected static final int explosionCount = 12; protected static int explosionCount = 12;
protected static final int spacing = 2; protected static int spacing = 2;
protected static final float power = 8; protected static float power = 8;
public tunnelArrow(EntityType<tunnelArrow> pEntityType, Level pLevel) { public tunnelArrow(EntityType<tunnelArrow> pEntityType, Level pLevel) {
super(pEntityType, pLevel); super(pEntityType, pLevel);
@ -43,9 +43,11 @@ public class tunnelArrow extends baseArrow{
} }
protected void explode() { protected void explode() {
// sync();
Vec3 rot = getTargetVec( - getXRot(), - getYRot(), 0); Vec3 rot = getTargetVec( - getXRot(), - getYRot(), 0);
for (int i = 0; i < explosionCount; i++) { for (int i = 0; i < explosionCount; i++) {
Vec3 pos = position().add(rot.multiply(i * spacing, i * spacing, i * spacing)); Vec3 pos = position().add(rot.multiply(i * spacing, i * spacing, i * spacing));
System.out.println(level().isClientSide + "|" + i + "|" + pos + "|" + getXRot() + "|" + getYRot());
level().explode(this, pos.x, pos.y, pos.z, level().explode(this, pos.x, pos.y, pos.z,
power, Level.ExplosionInteraction.TNT); power, Level.ExplosionInteraction.TNT);
} }
@ -60,10 +62,14 @@ public class tunnelArrow extends baseArrow{
@Override @Override
public void spawnParticles(float partialTicks) { public void spawnParticles(float partialTicks) {
for (int i = 1; i <= ConfigClient.calcPCount(5); i++) { for (int i = 1; i <= ConfigClient.calcPCount(3); i++) {
double m = (double) level().getRandom().nextIntBetweenInclusive(- 100, 100) / 100; double m = (double) level().getRandom().nextIntBetweenInclusive(- 100, 100) / 100;
Vec3 DeltaMovement = getDeltaMovement(); Vec3 DeltaMovement = getDeltaMovement();
Vec3 pos = particlePos(0.5); Vec3 pos = new Vec3(
(double) level().getRandom().nextIntBetweenInclusive(-5, 5) / 10,
0,
(double) level().getRandom().nextIntBetweenInclusive(-5, 5) / 10
).normalize().multiply(m, m, m).add(getPosition(partialTicks));
level().addParticle(particles.TUNNEL_ARROW_PARTICLE.get(), pos.x, pos.y, pos.z, DeltaMovement.x, DeltaMovement.y, DeltaMovement.z); level().addParticle(particles.TUNNEL_ARROW_PARTICLE.get(), pos.x, pos.y, pos.z, DeltaMovement.x, DeltaMovement.y, DeltaMovement.z);
} }
} }

View File

@ -1,5 +1,6 @@
package com.jenny.enhancedexplosives.entities.client; package com.jenny.enhancedexplosives.entities.client;
import com.jenny.enhancedexplosives.config.ConfigClient;
import com.jenny.enhancedexplosives.entities.tnt.basePrimedTNT; import com.jenny.enhancedexplosives.entities.tnt.basePrimedTNT;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis; import com.mojang.math.Axis;

View File

@ -1,6 +1,8 @@
package com.jenny.enhancedexplosives.entities.client; package com.jenny.enhancedexplosives.entities.client;
import com.jenny.enhancedexplosives.entities.arrows.baseArrow; import com.jenny.enhancedexplosives.entities.arrows.baseArrow;
import com.jenny.enhancedexplosives.config.*;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.MultiBufferSource;
@ -11,6 +13,7 @@ import net.minecraft.client.renderer.entity.TntMinecartRenderer;
import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class TNTArrowRenderer extends EntityRenderer<baseArrow> { public class TNTArrowRenderer extends EntityRenderer<baseArrow> {

View File

@ -2,6 +2,7 @@ package com.jenny.enhancedexplosives.entities.throwable;
import com.jenny.enhancedexplosives.entities.entities; import com.jenny.enhancedexplosives.entities.entities;
import com.jenny.enhancedexplosives.entities.tnt.basePrimedTNT; import com.jenny.enhancedexplosives.entities.tnt.basePrimedTNT;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;

View File

@ -23,20 +23,20 @@ public abstract class basePrimedTNT extends Entity implements TraceableEntity {
private LivingEntity owner; private LivingEntity owner;
private int fuse = 0; private int fuse = 0;
public basePrimedTNT(EntityType<? extends basePrimedTNT> pEntityType, @NotNull Level pLevel, @Nullable LivingEntity owner) { public basePrimedTNT(EntityType<? extends basePrimedTNT> pEntityType, Level pLevel, @Nullable LivingEntity owner) {
super(pEntityType, pLevel); super(pEntityType, pLevel);
commonInit(pLevel, owner); commonInit(pLevel, owner);
this.fuse = getFuse(); this.fuse = getFuse();
} }
private void commonInit(@NotNull Level pLevel, @Nullable LivingEntity owner) { private void commonInit(Level pLevel, @Nullable LivingEntity owner) {
double d0 = pLevel.random.nextDouble() * (double)((float)Math.PI * 2F); double d0 = pLevel.random.nextDouble() * (double)((float)Math.PI * 2F);
this.setDeltaMovement(-Math.sin(d0) * 0.02D, (double)0.2F, -Math.cos(d0) * 0.02D); this.setDeltaMovement(-Math.sin(d0) * 0.02D, (double)0.2F, -Math.cos(d0) * 0.02D);
this.blocksBuilding = true; this.blocksBuilding = true;
this.setOwner(owner); this.owner = owner;
} }
public basePrimedTNT(EntityType<? extends basePrimedTNT> pEntityType, @NotNull Level pLevel, @Nullable LivingEntity owner, Vec3 pos, int fuse, float power) { public basePrimedTNT(EntityType<? extends basePrimedTNT> pEntityType, Level pLevel, @Nullable LivingEntity owner, Vec3 pos, int fuse, float power) {
super(pEntityType, pLevel); super(pEntityType, pLevel);
commonInit(pLevel, owner); commonInit(pLevel, owner);
setPos(pos); setPos(pos);
@ -67,7 +67,7 @@ public abstract class basePrimedTNT extends Entity implements TraceableEntity {
public void tick() { public void tick() {
if (level().isClientSide) { if (level().isClientSide) {
if (ConfigClient.tntParticles.get()) { if (ConfigClient.tntParticles) {
spawnParticles(); spawnParticles();
} }
} }

View File

@ -1,25 +1,23 @@
package com.jenny.enhancedexplosives.entities.tnt; package com.jenny.enhancedexplosives.entities.tnt;
import com.jenny.enhancedexplosives.blocks.blocks; import com.jenny.enhancedexplosives.blocks.blocks;
import com.jenny.enhancedexplosives.config.ConfigClient;
import com.jenny.enhancedexplosives.config.ConfigServer;
import com.jenny.enhancedexplosives.entities.entities; import com.jenny.enhancedexplosives.entities.entities;
import com.jenny.enhancedexplosives.config.ConfigClient;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.*;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.ai.targeting.TargetingConditions;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
public class homingPrimedTNT extends basePrimedTNT { public class homingPrimedTNT extends basePrimedTNT {
private static final EntityDataAccessor<Float> DATA_SPEED_ID = SynchedEntityData.defineId(homingPrimedTNT.class, EntityDataSerializers.FLOAT); private static final EntityDataAccessor<Float> DATA_SPEED_ID = SynchedEntityData.defineId(homingPrimedTNT.class, EntityDataSerializers.FLOAT);
@ -53,34 +51,10 @@ public class homingPrimedTNT extends basePrimedTNT {
} }
public void findTarget() { public void findTarget() {
target = closestEntity(getEntities());
}
private LivingEntity closestEntity(List<LivingEntity> entities) {
double dist = Double.MAX_VALUE;
LivingEntity target = null;
for (LivingEntity e : entities) {
double newDist = e.position().distanceTo(position());
if (newDist < dist) {
target = e;
dist = newDist;
}
}
return target;
}
protected List<LivingEntity> getEntities() {
List<LivingEntity> ret_list = new ArrayList<>();
Vec3 corner1 = this.position().subtract(15, 15, 15); Vec3 corner1 = this.position().subtract(15, 15, 15);
Vec3 corner2 = this.position().add(15, 15, 15); Vec3 corner2 = this.position().add(15, 15, 15);
AABB boundingBox = new AABB(corner1, corner2); AABB boundingBox = new AABB(corner1, corner2);
target = this.level().getNearestEntity(LivingEntity.class, TargetingConditions.forNonCombat(), null, this.getX(), this.getY(), this.getZ(), boundingBox);
for (LivingEntity entity : level().getEntitiesOfClass(LivingEntity.class, boundingBox)) {
if (level().getPlayerByUUID(entity.getUUID()) == null || ConfigServer.homingAtPlayers.get()) { // prevent aiming at player if config says so
ret_list.add(entity);
}
}
return ret_list;
} }
@Override @Override

View File

@ -34,7 +34,8 @@ public class repulsivePrimedTNT extends basePrimedTNT {
double dist = getTargetDist(target); double dist = getTargetDist(target);
float speed = getSpeed(); float speed = getSpeed();
Vec3 mult = new Vec3(speed / dist, speed / dist, speed / dist); Vec3 mult = new Vec3(speed / dist, speed / dist, speed / dist);
return target.position().subtract(this.position()).normalize().multiply(mult); Vec3 ret = target.position().subtract(this.position()).normalize().multiply(mult);
return ret;
} }
public double getTargetDist(Entity target) { public double getTargetDist(Entity target) {

View File

@ -3,9 +3,16 @@ package com.jenny.enhancedexplosives;
import com.jenny.enhancedexplosives.particles.ArrowParticle; import com.jenny.enhancedexplosives.particles.ArrowParticle;
import com.jenny.enhancedexplosives.particles.particles; import com.jenny.enhancedexplosives.particles.particles;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.TextureSheetParticle;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleType;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraftforge.client.event.RegisterParticleProvidersEvent; import net.minecraftforge.client.event.RegisterParticleProvidersEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.RegistryObject;
import java.util.Iterator;
import static com.jenny.enhancedexplosives.EnhancedExplosives.MODID; import static com.jenny.enhancedexplosives.EnhancedExplosives.MODID;

View File

@ -1,21 +1,10 @@
package com.jenny.enhancedexplosives.items; package com.jenny.enhancedexplosives.items;
import com.jenny.enhancedexplosives.entities.arrows.baseArrow;
import com.jenny.enhancedexplosives.entities.entities;
import net.minecraft.core.Position;
import net.minecraft.core.dispenser.AbstractProjectileDispenseBehavior;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.DispenserBlock;
import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject; import net.minecraftforge.registries.RegistryObject;
import org.jetbrains.annotations.NotNull;
import static com.jenny.enhancedexplosives.EnhancedExplosives.MODID; import static com.jenny.enhancedexplosives.EnhancedExplosives.MODID;
@ -31,28 +20,4 @@ public class items {
public static void register(IEventBus bus) { public static void register(IEventBus bus) {
ITEMS.register(bus); ITEMS.register(bus);
} }
public static void registerDispenser() {
class ArrowDispenseBehaviour extends AbstractProjectileDispenseBehavior {
private final EntityType<? extends baseArrow> arrowType;
public ArrowDispenseBehaviour(EntityType<? extends baseArrow> arrow) {
this.arrowType = arrow;
}
@Override
protected @NotNull Projectile getProjectile(@NotNull Level pLevel, @NotNull Position pPosition, @NotNull ItemStack pStack) {
baseArrow arrow = arrowType.create(pLevel);
assert arrow != null;
arrow.setPos(pPosition.x(), pPosition.y(), pPosition.z());
arrow.pickup = AbstractArrow.Pickup.ALLOWED;
return arrow;
}
}
DispenserBlock.registerBehavior(TNT_ARROW.get(), new ArrowDispenseBehaviour(entities.ARROW_TNT.get()));
DispenserBlock.registerBehavior(CONCUSSIVE_ARROW.get(), new ArrowDispenseBehaviour(entities.ARROW_CONCUSSIVE.get()));
DispenserBlock.registerBehavior(CARPET_ARROW.get(), new ArrowDispenseBehaviour(entities.ARROW_CARPET.get()));
DispenserBlock.registerBehavior(TUNNEL_ARROW.get(), new ArrowDispenseBehaviour(entities.ARROW_TUNNEL.get()));
}
} }

View File

@ -1,15 +0,0 @@
{
"type": "minecraft:crafting_shapeless",
"category": "redstone",
"ingredients":[
{
"item": "minecraft:tnt"
},
{
"item": "minecraft:piston"
}
],
"result": {
"item": "enhancedexplosives:tnt_black_hole"
}
}