Merge pull request #365 from StevenRS11/1.20.1-multiplatform

various fixes
This commit is contained in:
Waterpicker 2023-11-15 22:33:17 -06:00 committed by GitHub
commit e7642bba53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 88 deletions

View file

@ -172,6 +172,7 @@ public final class ModConfig implements ConfigData {
@RequiresRestart @RequiresRestart
@Tooltip private WorldList worldsLeadingToLimbo = new WorldList(List.of(), false); @Tooltip private WorldList worldsLeadingToLimbo = new WorldList(List.of(), false);
@Tooltip public boolean hardcoreLimbo = false; @Tooltip public boolean hardcoreLimbo = false;
@Tooltip public int limboReturnDistance = 20000;
@Tooltip public float limboBlocksCorruptingOverworldAmount = 5; @Tooltip public float limboBlocksCorruptingOverworldAmount = 5;
public boolean shouldUseLimbo(ResourceKey<Level> level) { public boolean shouldUseLimbo(ResourceKey<Level> level) {
return worldsLeadingToLimbo.blacklist != worldsLeadingToLimbo.list.contains(level.location().toString()); return worldsLeadingToLimbo.blacklist != worldsLeadingToLimbo.list.contains(level.location().toString());

View file

@ -59,7 +59,7 @@ public final class ModItems {
public static final RegistrySupplier<Item> RIFT_REMOVER = register("rift_remover", properties -> new RiftRemoverItem(properties.stacksTo(1).durability(100))); public static final RegistrySupplier<Item> RIFT_REMOVER = register("rift_remover", properties -> new RiftRemoverItem(properties.stacksTo(1).durability(100)));
public static final RegistrySupplier<Item> RIFT_SIGNATURE = register("rift_signature", properties -> new RiftSignatureItem(properties.stacksTo(1).durability(1))); public static final RegistrySupplier<Item> RIFT_SIGNATURE = register("rift_signature", properties -> new RiftSignatureItem(properties.stacksTo(1).durability(1),true));
public static final RegistrySupplier<Item> STABILIZED_RIFT_SIGNATURE = register("stabilized_rift_signature", properties -> new StabilizedRiftSignatureItem(properties.stacksTo(1).durability(20))); public static final RegistrySupplier<Item> STABILIZED_RIFT_SIGNATURE = register("stabilized_rift_signature", properties -> new StabilizedRiftSignatureItem(properties.stacksTo(1).durability(20)));

View file

@ -39,9 +39,12 @@ import java.util.function.BiFunction;
public class RiftSignatureItem extends Item { public class RiftSignatureItem extends Item {
public static final String ID = "rift_signature"; public static final String ID = "rift_signature";
public boolean shouldclear;
public RiftSignatureItem(Item.Properties settings, boolean clear) {
public RiftSignatureItem(Item.Properties settings) {
super(settings); super(settings);
shouldclear = clear;
} }
@Override @Override
@ -111,11 +114,11 @@ public class RiftSignatureItem extends Item {
// } // }
if(placedRiftLogic != null) { if(placedRiftLogic != null) {
placedRiftLogic.getRift(target.getWorld(), target.pos).ifPresent(a -> a.setDestination(RiftReference.tryMakeRelative(target, source))); placedRiftLogic.getRift((ServerLevel) world, pos).ifPresent(a -> a.setDestination(RiftReference.tryMakeRelative(source, target)));
} }
if((placedRiftLogic = PlacementLogic.getLogic(world, pos)) != null) { if((placedRiftLogic = PlacementLogic.getLogic(target.getWorld(), target.pos)) != null) {
placedRiftLogic.getRift((ServerLevel) world, pos).ifPresent(a -> a.setDestination(RiftReference.tryMakeRelative(source, target))); placedRiftLogic.getRift(target.getWorld(), target.pos).ifPresent(a -> a.setDestination(RiftReference.tryMakeRelative(target, source)));
} }
@ -135,8 +138,9 @@ public class RiftSignatureItem extends Item {
stack.hurtAndBreak(1, player, a -> {}); // TODO: calculate damage based on position? stack.hurtAndBreak(1, player, a -> {}); // TODO: calculate damage based on position?
if(shouldclear){
clearSource(stack); clearSource(stack);
}
player.displayClientMessage(Component.translatable(this.getDescriptionId() + ".created"), true); player.displayClientMessage(Component.translatable(this.getDescriptionId() + ".created"), true);
// null = send sound to the player too, we have to do this because this code is not run client-side // null = send sound to the player too, we have to do this because this code is not run client-side
world.playSound(null, player.blockPosition(), ModSoundEvents.RIFT_END.get(), SoundSource.BLOCKS, 0.6f, 1); world.playSound(null, player.blockPosition(), ModSoundEvents.RIFT_END.get(), SoundSource.BLOCKS, 0.6f, 1);

View file

@ -22,91 +22,12 @@ import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.rift.targets.RiftReference; import org.dimdev.dimdoors.rift.targets.RiftReference;
import org.dimdev.dimdoors.sound.ModSoundEvents; import org.dimdev.dimdoors.sound.ModSoundEvents;
public class StabilizedRiftSignatureItem extends Item { // TODO: common superclass with rift signature public class StabilizedRiftSignatureItem extends RiftSignatureItem { // TODO: common superclass with rift signature
public static final String ID = "stabilized_rift_signature"; public static final String ID = "stabilized_rift_signature";
public StabilizedRiftSignatureItem(Item.Properties settings) { public StabilizedRiftSignatureItem(Item.Properties settings) {
super(settings); super(settings,false);
} }
@Override
public boolean isFoil(ItemStack stack) {
return stack.getTag() != null && stack.getTag().contains("destination");
}
@Override
public InteractionResult useOn(UseOnContext itemUsageContext) {
Player player = itemUsageContext.getPlayer();
Level world = itemUsageContext.getLevel();
BlockPos pos = itemUsageContext.getClickedPos();
InteractionHand hand = itemUsageContext.getHand();
Direction side = itemUsageContext.getClickedFace();
BlockPlaceContext itemPlacementContext = new BlockPlaceContext(itemUsageContext);
ItemStack stack = player.getItemInHand(hand);
pos = world.getBlockState(pos).getBlock().canBeReplaced(world.getBlockState(pos), new BlockPlaceContext(itemUsageContext)) ? pos : pos.relative(side);
// Fail if the player can't place a block there
if (!player.mayUseItemAt(pos, side.getOpposite(), stack)) {
return InteractionResult.FAIL;
}
if (world.isClientSide) {
return InteractionResult.SUCCESS;
}
RotatedLocation target = getTarget(stack);
if (target == null) {
// The link signature has not been used. Store its current target as the first location.
setSource(stack, new RotatedLocation(world.dimension(), pos, player.getYRot(), 0));
player.displayClientMessage(Component.translatable(this.getDescriptionId() + ".stored"), true);
world.playSound(null, player.blockPosition(), ModSoundEvents.RIFT_START.get(), SoundSource.BLOCKS, 0.6f, 1);
} else {
// Place a rift at the target point
if (target.getBlockState().getBlock() != ModBlocks.DETACHED_RIFT) {
if (!target.getBlockState().getBlock().canBeReplaced(world.getBlockState(target.getBlockPos()), itemPlacementContext)) {
player.displayClientMessage(Component.translatable("tools.target_became_block"), true);
// Don't clear source, stabilized signatures always stay bound
return InteractionResult.FAIL;
}
Level targetWorld = DimensionalDoors.getWorld(target.world);
targetWorld.setBlockAndUpdate(target.getBlockPos(), ModBlocks.DETACHED_RIFT.get().defaultBlockState());
DetachedRiftBlockEntity rift1 = (DetachedRiftBlockEntity) target.getBlockEntity();
rift1.register();
}
// Place a rift at the source point
world.setBlockAndUpdate(pos, ModBlocks.DETACHED_RIFT.get().defaultBlockState());
DetachedRiftBlockEntity rift2 = (DetachedRiftBlockEntity) world.getBlockEntity(pos);
rift2.setDestination(RiftReference.tryMakeRelative(new Location((ServerLevel) world, pos), target));
rift2.register();
stack.hurtAndBreak(1, player, playerEntity -> {});
player.displayClientMessage(Component.translatable(this.getDescriptionId() + ".created"), true);
world.playSound(null, player.blockPosition(), ModSoundEvents.RIFT_END.get(), SoundSource.BLOCKS, 0.6f, 1);
}
return InteractionResult.SUCCESS;
}
public static void setSource(ItemStack itemStack, RotatedLocation destination) {
if (!itemStack.hasTag()) itemStack.setTag(new CompoundTag());
itemStack.getTag().put("destination", RotatedLocation.serialize(destination));
}
public static void clearSource(ItemStack itemStack) {
if (itemStack.hasTag()) {
itemStack.getTag().remove("destination");
}
}
public static RotatedLocation getTarget(ItemStack itemStack) {
if (itemStack.hasTag() && itemStack.getTag().contains("destination")) {
return RotatedLocation.deserialize(itemStack.getTag().getCompound("destination"));
} else {
return null;
}
}
} }

View file

@ -22,6 +22,7 @@ import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.block.UnravelUtil; import org.dimdev.dimdoors.block.UnravelUtil;
import org.dimdev.dimdoors.world.ModDimensions; import org.dimdev.dimdoors.world.ModDimensions;
import java.util.Random;
import java.util.UUID; import java.util.UUID;
import static org.dimdev.dimdoors.api.util.EntityUtils.chat; import static org.dimdev.dimdoors.api.util.EntityUtils.chat;
@ -84,6 +85,8 @@ public class EscapeTarget extends VirtualTarget implements EntityTarget { // TOD
} }
*/ */
destLoc = randomizeLimboReturn(destLoc, DimensionalDoors.getConfig().getLimboConfig().limboReturnDistance); //todo add minimum radius
if (destLoc != null && this.canEscapeLimbo) { if (destLoc != null && this.canEscapeLimbo) {
Location location = destLoc; //VirtualLocation.fromLocation(new Location((ServerWorld) entity.world, destLoc.pos)).projectToWorld(false); //TODO Fix world projection. Location location = destLoc; //VirtualLocation.fromLocation(new Location((ServerWorld) entity.world, destLoc.pos)).projectToWorld(false); //TODO Fix world projection.
@ -135,6 +138,19 @@ public class EscapeTarget extends VirtualTarget implements EntityTarget { // TOD
return nbt; return nbt;
} }
public static Location randomizeLimboReturn(Location playerSpawn, int range){
return new Location(playerSpawn.getWorld(), randomizeCoord(playerSpawn.getX(), range), playerSpawn.getY(), randomizeCoord(playerSpawn.getZ(),range));
}
public static int randomizeCoord(int coord, int range){
Random random = new Random();
int offset = random.nextInt(range + 1); // Generate a random offset within the range
boolean isPositive = random.nextBoolean(); // Randomly decide whether the offset should be positive or negative
// Apply the offset with the direction (positive or negative)
return isPositive ? coord + offset : coord - offset;
}
public static EscapeTarget fromNbt(CompoundTag nbt) { public static EscapeTarget fromNbt(CompoundTag nbt) {
return new EscapeTarget(nbt.getBoolean("canEscapeLimbo")); return new EscapeTarget(nbt.getBoolean("canEscapeLimbo"));
} }

View file

@ -361,6 +361,10 @@
"text.autoconfig.dimdoors.option.limbo.worldsLeadingToLimbo.list.@Tooltip": "List of the ids for worlds in the blacklsit/whitelist.", "text.autoconfig.dimdoors.option.limbo.worldsLeadingToLimbo.list.@Tooltip": "List of the ids for worlds in the blacklsit/whitelist.",
"text.autoconfig.dimdoors.option.limbo.worldsLeadingToLimbo.blacklist": "Is it a blacklist?", "text.autoconfig.dimdoors.option.limbo.worldsLeadingToLimbo.blacklist": "Is it a blacklist?",
"text.autoconfig.dimdoors.option.limbo.worldsLeadingToLimbo.blacklist.@Tooltip": "Boolean that determines if list is a blacklist or white list for worlds.", "text.autoconfig.dimdoors.option.limbo.worldsLeadingToLimbo.blacklist.@Tooltip": "Boolean that determines if list is a blacklist or white list for worlds.",
"text.autoconfig.dimdoors.option.limbo.limboReturnDistance.@Tooltip": "Distance from spawn that limbo returns you",
"text.autoconfig.dimdoors.option.limbo.limboReturnDistance": "Limbo Return Radius",
"text.autoconfig.dimdoors.category.graphics": "Graphics Settings", "text.autoconfig.dimdoors.category.graphics": "Graphics Settings",
"text.autoconfig.dimdoors.option.graphics.highlightRiftCoreFor": "Time to Highlight Rift Core", "text.autoconfig.dimdoors.option.graphics.highlightRiftCoreFor": "Time to Highlight Rift Core",