Skip to content

Commit

Permalink
Merge pull request #276 from DaFuqs/1.19-deeper-down
Browse files Browse the repository at this point in the history
Update great resprite branch
  • Loading branch information
Azzyypaaras authored Nov 12, 2023
2 parents 3632d89 + f4d9250 commit 9fd8aeb
Show file tree
Hide file tree
Showing 91 changed files with 8,011 additions and 449 deletions.
29 changes: 14 additions & 15 deletions src/main/java/de/dafuqs/spectrum/blocks/DeeperDownPortalBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import net.minecraft.state.*;
import net.minecraft.state.property.*;
import net.minecraft.util.*;
import net.minecraft.util.function.*;
import net.minecraft.util.hit.*;
import net.minecraft.util.math.*;
import net.minecraft.util.math.random.*;
Expand All @@ -32,25 +31,30 @@ public class DeeperDownPortalBlock extends Block {
private final static String CREATE_PORTAL_ADVANCEMENT_CRITERION = "opened_deeper_down_portal";

public static final BooleanProperty FACING_UP = Properties.UP;

protected static final VoxelShape SHAPE = Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 4D, 16.0D);
protected static final VoxelShape SHAPE_UP = Block.createCuboidShape(0.0D, 4D, 0.0D, 16.0D, 16.0D, 16.0D);

public DeeperDownPortalBlock(Settings settings) {
super(settings);
this.setDefaultState((this.stateManager.getDefaultState()).with(FACING_UP, false));
}


@Override
public boolean hasSidedTransparency(BlockState state) {
return true;
}

@Override
@SuppressWarnings("deprecation")
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) {
super.onBlockAdded(state, world, pos, oldState, notify);

if (!world.isClient) { // that should be a given, but in modded you never know
SpectrumS2CPacketSender.playParticleWithRandomOffsetAndVelocity((ServerWorld) world, Vec3d.ofCenter(pos), SpectrumParticleTypes.VOID_FOG, 30, new Vec3d(0.5, 0.0, 0.5), Vec3d.ZERO);
if (!hasNeighboringPortals(world, pos)) {
world.playSound(null, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, SpectrumSoundEvents.DEEPER_DOWN_PORTAL_OPEN, SoundCategory.BLOCKS, 0.75F, 0.75F);

for (PlayerEntity nearbyPlayer : world.getEntitiesByType(EntityType.PLAYER, Box.of(Vec3d.ofCenter(pos), 16D, 16D, 16D), LivingEntity::isAlive)) {
Support.grantAdvancementCriterion((ServerPlayerEntity) nearbyPlayer, CREATE_PORTAL_ADVANCEMENT_IDENTIFIER, CREATE_PORTAL_ADVANCEMENT_CRITERION);
}
Expand Down Expand Up @@ -86,11 +90,7 @@ private boolean hasNeighboringPortals(World world, BlockPos pos) {

@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if (state.get(FACING_UP)) {
return SHAPE_UP;
} else {
return SHAPE;
}
return state.get(FACING_UP) ? SHAPE_UP : SHAPE;
}

@Override
Expand All @@ -113,14 +113,13 @@ public void onEntityCollision(BlockState state, World world, BlockPos pos, Entit
if (world instanceof ServerWorld
&& !entity.hasVehicle()
&& !entity.hasPassengers()
&& entity.canUsePortals()
&& VoxelShapes.matchesAnywhere(VoxelShapes.cuboid(entity.getBoundingBox().offset((-pos.getX()), (-pos.getY()), (-pos.getZ()))), state.getOutlineShape(world, pos), BooleanBiFunction.AND)) {

&& entity.canUsePortals()) {

RegistryKey<World> currentWorldKey = world.getRegistryKey();
if (currentWorldKey == World.OVERWORLD) {
if (!entity.hasPortalCooldown()) {
entity.resetPortalCooldown();

// => teleport to DD
ServerWorld targetWorld = ((ServerWorld) world).getServer().getWorld(SpectrumDimensions.DIMENSION_KEY);
if (targetWorld != null) {
Expand Down
154 changes: 46 additions & 108 deletions src/main/java/de/dafuqs/spectrum/blocks/decay/DecayBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import de.dafuqs.spectrum.registries.*;
import net.fabricmc.api.*;
import net.minecraft.block.*;
import net.minecraft.block.piston.*;
import net.minecraft.enchantment.*;
import net.minecraft.entity.*;
import net.minecraft.item.*;
import net.minecraft.particle.*;
import net.minecraft.server.world.*;
import net.minecraft.state.*;
import net.minecraft.state.property.*;
import net.minecraft.tag.*;
import net.minecraft.util.*;
import net.minecraft.util.math.*;
import net.minecraft.util.math.random.Random;
Expand Down Expand Up @@ -48,27 +46,15 @@ public String asString() {

public static final EnumProperty<Conversion> CONVERSION = EnumProperty.of("conversion", Conversion.class);

/**
* Since Tag is not comparable we can not use a SortedMap for decayConversions
* here and therefore have to use an additional list for check order
*/
protected final Map<TagKey<Block>, BlockState> decayConversions = new LinkedHashMap<>();

/**
* Decay can only convert those blocks to more decay
*/
protected final TagKey<Block> whiteListBlockTag;
/**
* Decay is blocked by those blocks and can't jump over to them
*/
protected final TagKey<Block> blackListBlockTag;
protected final float spreadChance;
protected final boolean canSpreadToBlockEntities;
protected final float damageOnTouching;
protected final int tier;

public DecayBlock(Settings settings, TagKey<Block> whiteListBlockTag, TagKey<Block> blackListBlockTag, int tier, float damageOnTouching) {
public DecayBlock(Settings settings, float spreadChance, boolean canSpreadToBlockEntities, int tier, float damageOnTouching) {
super(settings);
this.whiteListBlockTag = whiteListBlockTag;
this.blackListBlockTag = blackListBlockTag;
this.spreadChance = spreadChance;
this.canSpreadToBlockEntities = canSpreadToBlockEntities;
this.damageOnTouching = damageOnTouching;
this.tier = tier;
}
Expand All @@ -78,17 +64,6 @@ protected void appendProperties(StateManager.Builder<Block, BlockState> stateMan
stateManager.add(CONVERSION);
}

/**
* If the decay jumps to sourceBlockState it will not place decay there, but destinationBlockState instead
* If a source block is not in one of those tags it will just be replaced with default decay
*
* @param sourceBlockTag The block tag checked for a conversion through decay
* @param conversionState The block state the source block is converted to
*/
public void addDecayConversion(TagKey<Block> sourceBlockTag, BlockState conversionState) {
this.decayConversions.put(sourceBlockTag, conversionState);
}

@Override
public void onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity) {
if (entity instanceof LivingEntity && !entity.isFireImmune() && !EnchantmentHelper.hasFrostWalker((LivingEntity) entity)) {
Expand All @@ -114,61 +89,16 @@ public void randomDisplayTick(BlockState state, World world, BlockPos pos, Rando
}
}

// jump to neighboring blocks
@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (canSpread(state)) {
float spreadChance = getSpreadChance();
if (spreadChance < 1.0F) {
if (random.nextFloat() > spreadChance) {
return;
}
}

Direction randomDirection = Direction.random(random);
tryConvert(world, state, pos, randomDirection);
}
}

protected boolean tryConvert(@NotNull World world, BlockState state, @NotNull BlockPos originPos, Direction direction) {
BlockPos targetBlockPos = originPos.offset(direction);

BlockState targetBlockState = world.getBlockState(targetBlockPos);
if (canSpreadTo(world, targetBlockPos, targetBlockState)) {
world.setBlockState(targetBlockPos, getConversionFor(state, targetBlockState));
return true;
}
return false;
}

public boolean canSpreadTo(World world, BlockPos targetBlockPos, BlockState stateAtTargetPos) {
private boolean canSpreadTo(World world, BlockPos targetBlockPos, BlockState stateAtTargetPos) {
if (SpectrumCommon.CONFIG.DecayIsStoppedByClaimMods && GenericClaimModsCompat.isProtected(world, targetBlockPos, null)) {
return false;
}

return (canSpreadToBlockEntities() || world.getBlockEntity(targetBlockPos) == null)
&& (canSpreadToAir() || !stateAtTargetPos.getCollisionShape(world, targetBlockPos).isEmpty()) // decay can convert decay of a lower tier
return (this.canSpreadToBlockEntities || world.getBlockEntity(targetBlockPos) == null)
&& (!(stateAtTargetPos.getBlock() instanceof DecayBlock decayBlock) || this.tier > decayBlock.tier) // decay can convert decay of a lower tier
&& (whiteListBlockTag == null || stateAtTargetPos.isIn(whiteListBlockTag))
&& (blackListBlockTag == null || !stateAtTargetPos.isIn(blackListBlockTag))
&& (stateAtTargetPos.getBlock() == Blocks.BEDROCK || (stateAtTargetPos.getBlock().getHardness() > -1.0F && stateAtTargetPos.getBlock().getBlastResistance() < 10000.0F));
}

public BlockState getConversionFor(BlockState stateToSpread, BlockState stateToSpreadTo) {
for (Map.Entry<TagKey<Block>, BlockState> conversion : this.decayConversions.entrySet()) {
if (stateToSpreadTo.isIn(conversion.getKey())) {
return conversion.getValue();
}
}
return getSpreadState(stateToSpread);
}

@Override
public PistonBehavior getPistonBehavior(BlockState state) {
return PistonBehavior.BLOCK;
}


/**
* If a neighboring block is updated (placed by a player?), and that can be converted
* schedule a tick to convert it faster. => User gets quick reaction
Expand All @@ -179,55 +109,63 @@ public void neighborUpdate(BlockState state, World world, BlockPos pos, Block pr
super.neighborUpdate(state, world, pos, previousBlock, fromPos, notify);

if (previousBlock == Blocks.AIR) {
Block newBlock = world.getBlockState(fromPos).getBlock();
BlockState updatedState = world.getBlockState(fromPos);
Block updatedBlock = updatedState.getBlock();

if (canSpread(state) && !(newBlock instanceof DecayBlock) && !(newBlock instanceof DecayAwayBlock)) {
for (Map.Entry<TagKey<Block>, BlockState> conversion : this.decayConversions.entrySet()) {
if (state.isIn(conversion.getKey())) {
world.createAndScheduleBlockTick(pos, this, 40 + world.random.nextInt(200), TickPriority.EXTREMELY_LOW);
break;
}
if (!(updatedBlock instanceof DecayBlock) && !(updatedBlock instanceof DecayAwayBlock)) {
@Nullable BlockState spreadState = this.getSpreadState(state, updatedState);
if (spreadState != null) {
world.createAndScheduleBlockTick(pos, this, 40 + world.random.nextInt(200), TickPriority.EXTREMELY_LOW);
}
}
}
}

@Override
public boolean hasRandomTicks(BlockState state) {
return this.canSpread(state);
}

@Override
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
this.randomTick(state, world, pos, random);

spreadToNeighboringBlock(state, world, pos);
trySpreadToRandomNeighboringBlock(state, world, pos);
}

private void spreadToNeighboringBlock(BlockState state, ServerWorld world, BlockPos pos) {
if (canSpread(state)) {
List<Direction> directions = new ArrayList<>(List.of(Direction.values()));
Collections.shuffle(directions);

for (Direction direction : directions) {
boolean converted = tryConvert(world, state, pos, direction);
if (converted) {
break;
}
// jump to neighboring blocks
@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (this.spreadChance < 1.0F) {
if (random.nextFloat() > this.spreadChance) {
return;
}
}

Direction randomDirection = Direction.random(random);
trySpreadInDirection(world, state, pos, randomDirection);
}

protected abstract float getSpreadChance();

protected abstract boolean canSpread(BlockState blockState);

protected abstract boolean canSpreadToBlockEntities();

protected abstract BlockState getSpreadState(BlockState previousState);
private void trySpreadToRandomNeighboringBlock(BlockState state, ServerWorld world, BlockPos pos) {
List<Direction> directions = new ArrayList<>(List.of(Direction.values()));
Collections.shuffle(directions);

for (Direction direction : directions) {
if (trySpreadInDirection(world, state, pos, direction)) {
break;
}
}
}

protected boolean canSpreadToAir() {
protected boolean trySpreadInDirection(@NotNull World world, BlockState state, @NotNull BlockPos originPos, Direction direction) {
BlockPos targetPos = originPos.offset(direction);
BlockState targetBlockState = world.getBlockState(targetPos);

if (canSpreadTo(world, targetPos, targetBlockState)) {
@Nullable BlockState spreadState = this.getSpreadState(state, targetBlockState);
if (spreadState != null) {
world.setBlockState(targetPos, spreadState);
}
return true;
}
return false;
}

protected abstract @Nullable BlockState getSpreadState(BlockState stateToSpreadFrom, BlockState stateToSpreadTo);

}
36 changes: 8 additions & 28 deletions src/main/java/de/dafuqs/spectrum/blocks/decay/FadingBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import de.dafuqs.spectrum.particle.*;
import de.dafuqs.spectrum.registries.*;
import net.minecraft.block.*;
import net.minecraft.block.piston.*;
import net.minecraft.entity.*;
import net.minecraft.item.*;
import net.minecraft.particle.*;
Expand All @@ -17,16 +16,7 @@
public class FadingBlock extends DecayBlock {

public FadingBlock(Settings settings) {
super(settings, SpectrumBlockTags.FADING_CONVERSIONS, null, 1, 1F);

setDefaultState(getStateManager().getDefaultState().with(CONVERSION, Conversion.NONE));
addDecayConversion(SpectrumBlockTags.FADING_SPECIAL_CONVERSIONS, this.getDefaultState().with(CONVERSION, Conversion.SPECIAL));
addDecayConversion(SpectrumBlockTags.FADING_CONVERSIONS, this.getDefaultState().with(CONVERSION, Conversion.DEFAULT));
}

@Override
public PistonBehavior getPistonBehavior(BlockState state) {
return PistonBehavior.NORMAL;
super(settings, SpectrumCommon.CONFIG.FadingDecayTickRate, SpectrumCommon.CONFIG.FadingCanDestroyBlockEntities, 1, 1F);
}

@Override
Expand All @@ -46,23 +36,13 @@ public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable Livi
}

@Override
protected float getSpreadChance() {
return SpectrumCommon.CONFIG.FadingDecayTickRate;
}

@Override
protected boolean canSpreadToBlockEntities() {
return SpectrumCommon.CONFIG.FadingCanDestroyBlockEntities;
}

@Override
protected boolean canSpread(BlockState blockState) {
return true;
}

@Override
protected BlockState getSpreadState(BlockState previousState) {
return this.getDefaultState().with(CONVERSION, Conversion.NONE);
protected @Nullable BlockState getSpreadState(BlockState stateToSpreadFrom, BlockState stateToSpreadTo) {
if (stateToSpreadTo.isIn(SpectrumBlockTags.FADING_SPECIAL_CONVERSIONS)) {
return stateToSpreadFrom.with(CONVERSION, Conversion.SPECIAL);
} else if (stateToSpreadTo.isIn(SpectrumBlockTags.FADING_CONVERSIONS)) {
return stateToSpreadFrom.with(CONVERSION, Conversion.DEFAULT);
}
return null;
}

}
Loading

0 comments on commit 9fd8aeb

Please sign in to comment.