Setup the framework for random chunks of different dimensions to be placed in limbo around the player as they spend time there.
This commit is contained in:
parent
0ae5e1ce6d
commit
46fede1d88
1 changed files with 96 additions and 2 deletions
|
@ -1,7 +1,13 @@
|
|||
package org.dimdev.dimdoors.mixin;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.server.network.ServerRecipeBook;
|
||||
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
|
||||
import org.dimdev.dimdoors.ModConfig;
|
||||
import org.dimdev.dimdoors.block.UnravelledFabricBlock;
|
||||
import org.dimdev.dimdoors.criteria.ModCriteria;
|
||||
import org.dimdev.dimdoors.enchantment.ModEnchants;
|
||||
import org.dimdev.dimdoors.entity.limbo.LimboEntranceSource;
|
||||
|
@ -12,7 +18,9 @@ import org.dimdev.dimdoors.network.ExtendedServerPlayNetworkHandler;
|
|||
import org.dimdev.dimdoors.network.packet.s2c.PlayerInventorySlotUpdateS2CPacket;
|
||||
import org.dimdev.dimdoors.world.ModDimensions;
|
||||
import org.dimdev.dimdoors.world.level.component.PlayerModifiersComponent;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
@ -30,10 +38,22 @@ import java.util.Random;
|
|||
|
||||
@Mixin(value = ServerPlayerEntity.class, priority = 900)
|
||||
public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
private ServerRecipeBook recipeBook;
|
||||
|
||||
@Shadow
|
||||
public abstract void readCustomDataFromNbt(NbtCompound nbt);
|
||||
|
||||
private static final float RANDOM_ACTION_CHANCE = 0.1F;
|
||||
private static final float CHANCE_TO_DECREASE_ARMOR_DURABILITY = 0.03F;
|
||||
private static final float CHANCE_TO_REPLACE_ITEMSLOT_WITH_UNRAVLED_FABRIC = 0.005F;
|
||||
private static final float CHANCE_TO_ENCHANT_WITH_FRAY = 0.01F;
|
||||
private static final float CHANCE_TO_MAKE_LIMBO_LIKE_OTHER_DIMENSIONS = 0.1F;
|
||||
private static final float RANDOM_INCREMENT_FRAY_CHANCE = 0.1F;
|
||||
private static final int CHUNK_SIZES = 25;
|
||||
private static final int POSITION_AWAY = 50;
|
||||
private static final float RANDOM_LIQUID_CHANCE = 0.7F;
|
||||
Random random = new Random();
|
||||
|
||||
public ServerPlayerEntityMixin(EntityType<? extends LivingEntity> entityType, World world) {
|
||||
|
@ -41,18 +61,92 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin {
|
|||
}
|
||||
|
||||
@Inject(method = "tick", at = @At("HEAD"), cancellable = true)
|
||||
public void mobTickMixin(CallbackInfo ci) {
|
||||
|
||||
public void playerTickMixin(CallbackInfo ci) {
|
||||
if (random.nextFloat() <= RANDOM_ACTION_CHANCE) {
|
||||
if(random.nextFloat() <= RANDOM_INCREMENT_FRAY_CHANCE && PlayerModifiersComponent.getFray((PlayerEntity) (Object)this) < 180) {
|
||||
PlayerModifiersComponent.incrementFray((PlayerEntity) (Object)this, 1);
|
||||
}
|
||||
if (PlayerModifiersComponent.getFray(this) >= 125) {
|
||||
doRandomFunction(this);
|
||||
}
|
||||
if(ModDimensions.isLimboDimension(((PlayerEntity)(Object)(this)).getEntityWorld())) {
|
||||
tryAddingFrayEnchantment((PlayerEntity) (Object)this);
|
||||
tryMakingLimboLikeOtherDimensions((PlayerEntity)(Object)this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private boolean isValidBlockToReplace(World world, BlockPos pos) {
|
||||
return world.getBlockState(pos.up()).isAir() && world.getBlockState(pos).getBlock() instanceof UnravelledFabricBlock;
|
||||
}
|
||||
private void makeLimboLikeOverworld(PlayerEntity player) {
|
||||
/*
|
||||
World world = player.getEntityWorld();
|
||||
BlockPos pos = player.getBlockPos().add(random.nextInt(random.nextInt(POSITION_AWAY)), 0, random.nextInt(POSITION_AWAY));
|
||||
if(random.nextFloat() <= RANDOM_LIQUID_CHANCE) {
|
||||
makeSpotOfLiquid(world, pos, Blocks.WATER.getDefaultState(), 3);
|
||||
}
|
||||
BlockPos.iterateOutwards(pos, CHUNK_SIZES, 15, CHUNK_SIZES).forEach( (blockPos -> {
|
||||
if(isValidBlockToReplace(world, blockPos)) {
|
||||
world.setBlockState(blockPos, Blocks.GRASS_BLOCK.getDefaultState());
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
private void makeLimboLikeEnd(PlayerEntity player) {
|
||||
/*
|
||||
World world = player.getEntityWorld();
|
||||
BlockPos pos = player.getBlockPos().add(random.nextInt(POSITION_AWAY), 0, random.nextInt(POSITION_AWAY));
|
||||
BlockPos.iterateOutwards(pos, CHUNK_SIZES, 15, CHUNK_SIZES).forEach( (blockPos -> {
|
||||
if(isValidBlockToReplace(world, blockPos)) {
|
||||
world.setBlockState(blockPos, Blocks.END_STONE.getDefaultState());
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
private void makeSpotOfLiquid(World world, BlockPos pos, BlockState state, int range) {
|
||||
|
||||
BlockPos.iterateOutwards(pos, random.nextInt(range), random.nextInt(range), random.nextInt(range)).forEach( (blockPos -> {
|
||||
if(isValidBlockToReplace(world, blockPos)) {
|
||||
world.setBlockState(blockPos, state);
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
private void makeLimboLikeNether(PlayerEntity player) {
|
||||
/*
|
||||
World world = player.getEntityWorld();
|
||||
BlockPos pos = player.getBlockPos().add(random.nextInt(POSITION_AWAY), 0, random.nextInt(POSITION_AWAY));
|
||||
if(random.nextFloat() <= RANDOM_LIQUID_CHANCE) {
|
||||
makeSpotOfLiquid(world, pos, Blocks.LAVA.getDefaultState(), 10);
|
||||
}
|
||||
BlockPos.iterateOutwards(pos, CHUNK_SIZES, 15, CHUNK_SIZES).forEach( (blockPos -> {
|
||||
if(isValidBlockToReplace(world, blockPos)) {
|
||||
world.setBlockState(blockPos, Blocks.NETHERRACK.getDefaultState());
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
*/
|
||||
}
|
||||
private void tryMakingLimboLikeOtherDimensions(PlayerEntity player) {
|
||||
if(random.nextFloat() > CHANCE_TO_MAKE_LIMBO_LIKE_OTHER_DIMENSIONS) {
|
||||
return;
|
||||
}
|
||||
switch (random.nextInt(3)) {
|
||||
case 0 : makeLimboLikeOverworld(player); break;
|
||||
case 1 : makeLimboLikeNether(player); break;
|
||||
case 2 : makeLimboLikeEnd(player); break;
|
||||
}
|
||||
}
|
||||
|
||||
private void doRandomFunction(LivingEntity player) {
|
||||
switch (random.nextInt(2)) {
|
||||
|
|
Loading…
Reference in a new issue