Skip to content

Commit

Permalink
feat: tag usage for dragon block break / drop
Browse files Browse the repository at this point in the history
  • Loading branch information
SiverDX authored and TheBv committed Dec 26, 2023
1 parent 98273a3 commit d9f4e1e
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"values": [
"#forge:chests",
"minecraft:end_stone",
"minecraft:iron_bars"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"values": [
"#minecraft:dirt",
"#forge:stone",
"#iceandfire:dragon_environment_blocks",
"minecraft:grass_block"
]
}
7 changes: 2 additions & 5 deletions src/main/java/com/github/alexthe666/iceandfire/IafConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ public class IafConfig {
public static int generateDragonDenChance = 260;
public static int generateDragonRoostChance = 480;
public static int dragonDenGoldAmount = 4;
public static List<? extends String> blacklistedBreakBlocks = Lists.newArrayList();
public static List<? extends String> noDropBreakBlocks = Lists.newArrayList("minecraft:stone", "minecraft:dirt", "minecraft:grass_block");
public static boolean blacklistBreakBlocksIsWhiteList = false;
public static boolean spawnGlaciers = true;
public static int glacierSpawnChance = 4;
public static int oreToStoneRatioForDragonCaves = 45;
Expand Down Expand Up @@ -276,8 +273,8 @@ public static void bakeServer(final ModConfig config) {
chunkLoadSummonCrystal = ConfigHolder.SERVER.chunkLoadSummonCrystal.get();
dangerousWorldGenDistanceLimit = ConfigHolder.SERVER.dangerousWorldGenDistanceLimit.get();
dangerousWorldGenSeparationLimit = ConfigHolder.SERVER.dangerousWorldGenSeparationLimit.get();
blacklistedBreakBlocks = ConfigHolder.SERVER.blacklistedBreakBlocks.get();
noDropBreakBlocks = ConfigHolder.SERVER.noDropBreakBlocks.get();
// blacklistedBreakBlocks = ConfigHolder.SERVER.blacklistedBreakBlocks.get();
// noDropBreakBlocks = ConfigHolder.SERVER.noDropBreakBlocks.get();
dragonFlightSpeedMod = ConfigHolder.SERVER.dragonFlightSpeedMod.get();
hippogryphFlightSpeedMod = ConfigHolder.SERVER.hippogryphFlightSpeedMod.get();
hippocampusSwimSpeedMod = ConfigHolder.SERVER.hippocampusSwimSpeedMod.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public void tryDropExperience(@NotNull ServerLevel level, @NotNull BlockPos pos,
super.tryDropExperience(level, pos, heldItem, amount);
}


// FIXME :: Unused -> popExperience(...)
protected int getExperience(RandomSource rand) {
if (this == IafBlockRegistry.SAPPHIRE_ORE.get()) {
return Mth.nextInt(rand, 3, 7);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ public class ServerConfig {
public final ForgeConfigSpec.BooleanValue chunkLoadSummonCrystal;
public ForgeConfigSpec.IntValue dangerousWorldGenDistanceLimit;
public ForgeConfigSpec.IntValue dangerousWorldGenSeparationLimit;
public ForgeConfigSpec.ConfigValue<List<? extends String>> blacklistedBreakBlocks;
public ForgeConfigSpec.ConfigValue<List<? extends String>> noDropBreakBlocks;
public final ForgeConfigSpec.DoubleValue dragonFlightSpeedMod;
public final ForgeConfigSpec.DoubleValue hippogryphFlightSpeedMod;
public final ForgeConfigSpec.DoubleValue hippocampusSwimSpeedMod;
Expand Down Expand Up @@ -171,12 +169,6 @@ public ServerConfig(final ForgeConfigSpec.Builder builder) {
this.dragonGriefing = buildInt(builder, "Dragon Griefing", "all", 0, 0, 2, "Dragon griefing - 2 is no griefing, 1 is breaking weak blocks, 0 is default. This value is also affected by minecrafts mob griefing rule.");
this.tamedDragonGriefing = buildBoolean(builder, "Tamed Dragon Griefing", "all", true, "True if tamed dragons can follow the griefing rules.");
this.dragonBlockBreakingDropChance = buildDouble(builder, "Dragon Block Breaking Drop Chance", "all", 0.1F, 0.0F, 1.0F, "The percentage chance for a block to drop as an item when a dragon breaks it.");
blacklistedBreakBlocks = builder
.comment("Blocks that a dragon cannot break. Use the format like \"minecraft:chest\" or \"rats:block_of_cheese\" ")
.defineList("blacklistedBreakBlocks", Lists.newArrayList(), o -> o instanceof String);
noDropBreakBlocks = builder
.comment("Blocks that a dragon can break, but won't spawn drops for. Use the format like \"minecraft:stone\" or \"rats:block_of_cheese\" ")
.defineList("noDropBreakBlocks", Lists.newArrayList("minecraft:stone", "minecraft:dirt", "minecraft:grass_block"), o -> o instanceof String);
builder.pop();
builder.push("Attributes");
this.dragonEggTime = buildInt(builder, "Dragon Egg Hatch Time", "all", 7200, 1, Integer.MAX_VALUE, "How long it takes(in ticks) for a dragon egg to hatch");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class IafBlockTags extends BlockTagsProvider {
public static TagKey<Block> ICE_DRAGON_CAVE_ORES = createKey("ice_dragon_cave_ores");
public static TagKey<Block> LIGHTNING_DRAGON_CAVE_ORES = createKey("lightning_dragon_cave_ores");

public static TagKey<Block> DRAGON_BLOCK_BREAK_BLACKLIST = createKey("dragon_block_break_blacklist");
public static TagKey<Block> DRAGON_BLOCK_BREAK_NO_DROPS = createKey("dragon_block_break_no_drops");

public IafBlockTags(PackOutput output, CompletableFuture<HolderLookup.Provider> future, ExistingFileHelper helper) {
super(output, future, IceAndFire.MODID, helper);
}
Expand Down Expand Up @@ -90,6 +93,17 @@ protected void addTags(HolderLookup.Provider pProvider) {
tag(LIGHTNING_DRAGON_CAVE_ORES)
.add(Blocks.BUDDING_AMETHYST);

tag(DRAGON_BLOCK_BREAK_BLACKLIST)
.addTag(Tags.Blocks.CHESTS)
.add(Blocks.END_STONE)
.add(Blocks.IRON_BARS);

tag(DRAGON_BLOCK_BREAK_NO_DROPS)
.addTag(BlockTags.DIRT)
.addTag(Tags.Blocks.STONE)
.addTag(DRAGON_ENVIRONMENT_BLOCKS)
.add(Blocks.GRASS_BLOCK);

tag(BlockTags.NEEDS_STONE_TOOL)
.add(IafBlockRegistry.SILVER_ORE.get())
.add(IafBlockRegistry.DEEPSLATE_SILVER_ORE.get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.github.alexthe666.iceandfire.block.IDragonProof;
import com.github.alexthe666.iceandfire.client.model.IFChainBuffer;
import com.github.alexthe666.iceandfire.client.model.util.LegSolverQuadruped;
import com.github.alexthe666.iceandfire.datagen.tags.IafBlockTags;
import com.github.alexthe666.iceandfire.datagen.tags.IafItemTags;
import com.github.alexthe666.iceandfire.entity.ai.*;
import com.github.alexthe666.iceandfire.entity.props.ChainProperties;
Expand Down Expand Up @@ -1479,7 +1480,7 @@ public void breakBlock(final BlockPos position) {
if (isBreakable(position, state, hardness, this)) {
this.setDeltaMovement(this.getDeltaMovement().multiply(0.6F, 1, 0.6F));
if (!level().isClientSide()) {
level().destroyBlock(position, random.nextFloat() <= IafConfig.dragonBlockBreakingDropChance && DragonUtils.canDropFromDragonBlockBreak(state));
level().destroyBlock(position, !state.is(IafBlockTags.DRAGON_BLOCK_BREAK_NO_DROPS) && random.nextFloat() <= IafConfig.dragonBlockBreakingDropChance );
}
}
}
Expand Down Expand Up @@ -1522,7 +1523,7 @@ protected boolean isBreakable(BlockPos pos, BlockState state, float hardness, En
state.getFluidState().isEmpty() && !state.getShape(level(), pos).isEmpty() &&
state.getDestroySpeed(level(), pos) >= 0F &&
state.getDestroySpeed(level(), pos) <= hardness &&
DragonUtils.canDragonBreak(state.getBlock(), entity) && this.canDestroyBlock(pos, state);
DragonUtils.canDragonBreak(state, entity) && this.canDestroyBlock(pos, state);
}

@Override
Expand Down Expand Up @@ -2786,7 +2787,7 @@ public void randomizeAttacks() {

@Override
public boolean shouldBlockExplode(@NotNull Explosion explosionIn, @NotNull BlockGetter worldIn, @NotNull BlockPos pos, BlockState blockStateIn, float explosionPower) {
return !(blockStateIn.getBlock() instanceof IDragonProof) && DragonUtils.canDragonBreak(blockStateIn.getBlock(), this);
return !(blockStateIn.getBlock() instanceof IDragonProof) && DragonUtils.canDragonBreak(blockStateIn, this);
}

public void tryScorchTarget() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ public static void destroyAreaCharge(final Level level, final BlockPos center, f
if (canBreakBlocks) {
if (dragon.getDragonStage() <= 3) {
BlockPos.betweenClosedStream(center.offset(-x, -y, -z), center.offset(x, y, z)).forEach(position -> {
Block block = level.getBlockState(position).getBlock();
BlockState state = level.getBlockState(position);

if (dragon.getRandom().nextFloat() * 3 > center.distSqr(position) && (block instanceof IDragonProof) && DragonUtils.canDragonBreak(block, dragon)) {
if (dragon.getRandom().nextFloat() * 3 > center.distSqr(position) && (state.getBlock() instanceof IDragonProof) && DragonUtils.canDragonBreak(state, dragon)) {
level.destroyBlock(position, false);
}

Expand Down Expand Up @@ -209,7 +209,7 @@ private static DamageSource getDamageSource(final EntityDragonBase dragon) {
private static void attackBlock(final Level level, final EntityDragonBase dragon, final BlockPos position) {
BlockState state = level.getBlockState(position);

if (state.getBlock() instanceof IDragonProof || !DragonUtils.canDragonBreak(state.getBlock(), dragon)) {
if (state.getBlock() instanceof IDragonProof || !DragonUtils.canDragonBreak(state, dragon)) {
return;
}

Expand Down Expand Up @@ -244,7 +244,7 @@ private static void attackBlock(final Level level, final EntityDragonBase dragon

BlockState stateAbove = level.getBlockState(position.above());

if (doPlaceBlock && transformed.isSolid() && stateAbove.getFluidState().isEmpty() && !stateAbove.canOcclude() && state.canOcclude() && DragonUtils.canDragonBreak(stateAbove.getBlock(), dragon)) {
if (doPlaceBlock && transformed.isSolid() && stateAbove.getFluidState().isEmpty() && !stateAbove.canOcclude() && state.canOcclude() && DragonUtils.canDragonBreak(stateAbove, dragon)) {
level.setBlockAndUpdate(position.above(), elementalBlock.defaultBlockState());
}
}
Expand All @@ -271,7 +271,7 @@ private static void causeExplosion(Level world, BlockPos center, EntityDragonBas
private static void destroyBlocks(Level world, BlockPos center, int x, int y, int z, double radius2, Entity destroyer) {
BlockPos.betweenClosedStream(center.offset(-x, -y, -z), center.offset(x, y, z)).forEach(pos -> {
if (center.distSqr(pos) <= radius2) {
if (world.random.nextFloat() * 3 > (float) center.distSqr(pos) / radius2 && !(world.getBlockState(pos).getBlock() instanceof IDragonProof) && DragonUtils.canDragonBreak(world.getBlockState(pos).getBlock(), destroyer)) {
if (world.random.nextFloat() * 3 > (float) center.distSqr(pos) / radius2 && !(world.getBlockState(pos).getBlock() instanceof IDragonProof) && DragonUtils.canDragonBreak(world.getBlockState(pos), destroyer)) {
world.destroyBlock(pos, false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.alexthe666.iceandfire.IafConfig;
import com.github.alexthe666.iceandfire.block.IafBlockRegistry;
import com.github.alexthe666.iceandfire.datagen.tags.IafBlockTags;
import com.github.alexthe666.iceandfire.entity.*;
import com.github.alexthe666.iceandfire.misc.IafTagRegistry;
import com.google.common.base.Predicate;
Expand All @@ -20,7 +21,6 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.phys.AABB;
Expand All @@ -29,15 +29,9 @@
import net.minecraftforge.registries.ForgeRegistries;

import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DragonUtils {


private static final Map<Block, Boolean> BLOCK_CACHE = new HashMap<>();

public static BlockPos getBlockInViewEscort(EntityDragonBase dragon) {
BlockPos escortPos = dragon.getEscortPosition();
BlockPos ground = dragon.level().getHeightmapPos(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, escortPos);
Expand Down Expand Up @@ -323,21 +317,14 @@ public static boolean isInHomeDimension(EntityDragonBase dragonBase) {
return (dragonBase.getHomeDimensionName() == null || getDimensionName(dragonBase.level()).equals(dragonBase.getHomeDimensionName()));
}

public static boolean canDragonBreak(Block block, Entity entity) {

if (!ForgeEventFactory.getMobGriefingEvent(entity.level(), entity))
public static boolean canDragonBreak(final BlockState state, final Entity entity) {
if (!ForgeEventFactory.getMobGriefingEvent(entity.level(), entity)) {
return false;
}

if (BLOCK_CACHE.containsKey(block))
return BLOCK_CACHE.get(block);

boolean value = block.getExplosionResistance() < 1200 &&
block != Blocks.END_STONE &&
block != Blocks.IRON_BARS &&
!isBlacklistedBlock(block);
Block block = state.getBlock();

BLOCK_CACHE.put(block, value);
return value;
return block.getExplosionResistance() < 1200 && !state.is(IafBlockTags.DRAGON_BLOCK_BREAK_BLACKLIST);
}

public static boolean hasSameOwner(TamableAnimal cockatrice, Entity entity) {
Expand Down Expand Up @@ -365,25 +352,6 @@ public static boolean canGrief(EntityDragonBase dragon) {

}

public static boolean isBlacklistedBlock(Block block) {
if (IafConfig.blacklistBreakBlocksIsWhiteList) {
for (String name : IafConfig.blacklistedBreakBlocks) {
//TODO: This might not work
if (name.equalsIgnoreCase(ForgeRegistries.BLOCKS.getKey(block).getNamespace())) {
return false;
}
}
return true;
} else {
for (String name : IafConfig.blacklistedBreakBlocks) {
if (name.equalsIgnoreCase(ForgeRegistries.BLOCKS.getKey(block).getNamespace())) {
return true;
}
}
return false;
}
}

public static boolean canHostilesTarget(Entity entity) {
if (entity instanceof Player && (entity.level().getDifficulty() == Difficulty.PEACEFUL || ((Player) entity).isCreative())) {
return false;
Expand Down Expand Up @@ -423,15 +391,6 @@ public static boolean onSameTeam(Entity entity1, Entity entity2) {
return def;
}

public static boolean canDropFromDragonBlockBreak(BlockState state) {
for (String name : IafConfig.noDropBreakBlocks) {
if (name.equalsIgnoreCase(ForgeRegistries.BLOCKS.getKey(state.getBlock()).getNamespace())) {
return false;
}
}
return true;
}

public static boolean isDreadBlock(BlockState state) {
Block block = state.getBlock();
return block == IafBlockRegistry.DREAD_STONE.get() || block == IafBlockRegistry.DREAD_STONE_BRICKS.get() || block == IafBlockRegistry.DREAD_STONE_BRICKS_CHISELED.get() ||
Expand Down

0 comments on commit d9f4e1e

Please sign in to comment.