This commit is contained in:
Hexugory 2024-05-22 18:25:06 -05:00
parent 9df4bcf87d
commit 3e06d33470
22 changed files with 304 additions and 299 deletions

View File

@ -33,7 +33,7 @@ repositories {
dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Fabric API. This is technically optional, but you probably want it anyway.

View File

@ -1,6 +1,6 @@
package net.touhoudiscord;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
public interface BuyStationCapable {
default void hardcoreredeploy_openBuyStationScreen(BlockPos blockPos) {

View File

@ -8,26 +8,26 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.HorizontalFacingBlock;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.projectile.FireworkRocketEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameMode;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.entity.projectile.FireworkRocketEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import net.touhoudiscord.block.BuyStation;
import net.touhoudiscord.block.BuyStationEntity;
import net.touhoudiscord.commands.RedeployPlayerCommand;
@ -47,24 +47,24 @@ public class HardcoreRedeploy implements ModInitializer {
public static final String MOD_ID = "hardcore_redeploy";
public static final Logger LOGGER = LoggerFactory.getLogger("hardcore_redeploy");
public static final StatusEffect REDEPLOYING = new RedeployingStatusEffect();
public static final Block BUY_STATION = Registry.register(Registries.BLOCK, new Identifier(HardcoreRedeploy.MOD_ID, "buy_station"), new BuyStation(FabricBlockSettings.create().nonOpaque().requiresTool().resistance(6).hardness(3)));
public static final Item BUY_STATION_ITEM = Registry.register(Registries.ITEM, new Identifier(HardcoreRedeploy.MOD_ID, "buy_station"), new BuyStationItem(HardcoreRedeploy.BUY_STATION, new FabricItemSettings()));
public static final Identifier BUY_STATION_SOUND_ID = new Identifier(HardcoreRedeploy.MOD_ID, "buy_station");
public static SoundEvent BUY_STATION_SOUND_EVENT = SoundEvent.of(BUY_STATION_SOUND_ID);
public static final MobEffect REDEPLOYING = new RedeployingStatusEffect();
public static final Block BUY_STATION = Registry.register(BuiltInRegistries.BLOCK, new ResourceLocation(HardcoreRedeploy.MOD_ID, "buy_station"), new BuyStation(FabricBlockSettings.of().noOcclusion().requiresCorrectToolForDrops().explosionResistance(6).destroyTime(3)));
public static final Item BUY_STATION_ITEM = Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(HardcoreRedeploy.MOD_ID, "buy_station"), new BuyStationItem(HardcoreRedeploy.BUY_STATION, new FabricItemSettings()));
public static final ResourceLocation BUY_STATION_SOUND_ID = new ResourceLocation(HardcoreRedeploy.MOD_ID, "buy_station");
public static SoundEvent BUY_STATION_SOUND_EVENT = SoundEvent.createVariableRangeEvent(BUY_STATION_SOUND_ID);
public static BlockEntityType<BuyStationEntity> BUY_STATION_ENTITY;
public static final Identifier SEND_REVIVES_UPDATE = new Identifier(HardcoreRedeploy.MOD_ID, "send_revives_update");
public static final Identifier REQUEST_REVIVE = new Identifier(HardcoreRedeploy.MOD_ID, "request_revive");
public static final Identifier SEND_REVIVE = new Identifier(HardcoreRedeploy.MOD_ID, "send_revive");
public static final Identifier SYNC_CONFIG = new Identifier(HardcoreRedeploy.MOD_ID, "sync_config");
public static final ResourceLocation SEND_REVIVES_UPDATE = new ResourceLocation(HardcoreRedeploy.MOD_ID, "send_revives_update");
public static final ResourceLocation REQUEST_REVIVE = new ResourceLocation(HardcoreRedeploy.MOD_ID, "request_revive");
public static final ResourceLocation SEND_REVIVE = new ResourceLocation(HardcoreRedeploy.MOD_ID, "send_revive");
public static final ResourceLocation SYNC_CONFIG = new ResourceLocation(HardcoreRedeploy.MOD_ID, "sync_config");
private static final ItemStack firework;
static {
firework = new ItemStack(Registries.ITEM.get(new Identifier("minecraft", "firework_rocket")));
NbtCompound nbt = new NbtCompound();
firework = new ItemStack(BuiltInRegistries.ITEM.get(new ResourceLocation("minecraft", "firework_rocket")));
CompoundTag nbt = new CompoundTag();
nbt.putByte("Flight", (byte)3);
firework.setSubNbt("Fireworks", nbt);
firework.addTagElement("Fireworks", nbt);
}
@ -75,32 +75,32 @@ public class HardcoreRedeploy implements ModInitializer {
GeckoLib.initialize();
ServerPlayNetworking.registerGlobalReceiver(REQUEST_REVIVE, (server, player, handler, buf, responseSender) -> {
UUID uuid = buf.readUuid();
UUID uuid = buf.readUUID();
BlockPos blockPos = buf.readBlockPos();
server.execute(() -> {
ServerPlayerEntity spectator = server.getPlayerManager().getPlayer(uuid);
ServerPlayer spectator = server.getPlayerList().getPlayer(uuid);
if (spectator == null) return;
BlockState invokingBlock = player.getWorld().getBlockState(blockPos);
BlockState invokingBlock = player.level().getBlockState(blockPos);
if (invokingBlock.getBlock() instanceof BuyStation && player.getPos().isInRange(blockPos.toCenterPos(), 5)) {
if (invokingBlock.getBlock() instanceof BuyStation && player.position().closerThan(blockPos.getCenter(), 5)) {
int cost = config.baseCost + config.additiveCost * RedeployStateSaver.getPlayerState(spectator).timesRevived;
boolean isCreative = player.interactionManager.getGameMode() == GameMode.CREATIVE;
boolean isCreative = player.gameMode.getGameModeForPlayer() == GameType.CREATIVE;
if (!isCreative && player.experienceLevel < cost) return;
Vec3d fireworkPos = blockPos.toCenterPos();
BlockState blockState = player.getWorld().getBlockState(blockPos);
Direction offset = blockState.get(HorizontalFacingBlock.FACING).rotateYClockwise();
if (blockState.get(BUY_STATION_PART) == BuyStation.BuyStationPart.AUX)
Vec3 fireworkPos = blockPos.getCenter();
BlockState blockState = player.level().getBlockState(blockPos);
Direction offset = blockState.getValue(HorizontalDirectionalBlock.FACING).getClockWise();
if (blockState.getValue(BUY_STATION_PART) == BuyStation.BuyStationPart.AUX)
offset = offset.getOpposite();
FireworkRocketEntity fireworkRocketEntity = new FireworkRocketEntity(player.getWorld(), fireworkPos.x + offset.getOffsetX() / 2., fireworkPos.y, fireworkPos.z + offset.getOffsetZ() / 2., firework);
player.getWorld().spawnEntity(fireworkRocketEntity);
FireworkRocketEntity fireworkRocketEntity = new FireworkRocketEntity(player.level(), fireworkPos.x + offset.getStepX() / 2., fireworkPos.y, fireworkPos.z + offset.getStepZ() / 2., firework);
player.level().addFreshEntity(fireworkRocketEntity);
if (!isCreative) player.setExperienceLevel(player.experienceLevel - cost);
if (!isCreative) player.setExperienceLevels(player.experienceLevel - cost);
((TimerAccess) server).hardcoreredeploy_redeployInTicks(spectator, player, 60L);
PacketByteBuf buf1 = PacketByteBufs.create();
FriendlyByteBuf buf1 = PacketByteBufs.create();
ServerPlayNetworking.send(spectator, SEND_REVIVE, buf1);
}
});
@ -114,18 +114,18 @@ public class HardcoreRedeploy implements ModInitializer {
});
});
BUY_STATION_ENTITY = Registry.register(Registries.BLOCK_ENTITY_TYPE,
new Identifier(HardcoreRedeploy.MOD_ID, "buy_station_entity"),
BUY_STATION_ENTITY = Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE,
new ResourceLocation(HardcoreRedeploy.MOD_ID, "buy_station_entity"),
FabricBlockEntityTypeBuilder.create(BuyStationEntity::new,
HardcoreRedeploy.BUY_STATION).build());
Registry.register(Registries.STATUS_EFFECT, new Identifier(HardcoreRedeploy.MOD_ID, "redeploying"), REDEPLOYING);
Registry.register(BuiltInRegistries.MOB_EFFECT, new ResourceLocation(HardcoreRedeploy.MOD_ID, "redeploying"), REDEPLOYING);
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> RedeployPlayerCommand.register(dispatcher));
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> SetRevivesCommand.register(dispatcher));
Registry.register(Registries.SOUND_EVENT, BUY_STATION_SOUND_ID, BUY_STATION_SOUND_EVENT);
Registry.register(BuiltInRegistries.SOUND_EVENT, BUY_STATION_SOUND_ID, BUY_STATION_SOUND_EVENT);
}
public static void syncConfig(MinecraftServer server, ServerPlayerEntity receiver) {
PacketByteBuf buf = PacketByteBufs.create();
public static void syncConfig(MinecraftServer server, ServerPlayer receiver) {
FriendlyByteBuf buf = PacketByteBufs.create();
buf.writeInt(HardcoreRedeployConfigHandler.config.baseCost);
buf.writeInt(HardcoreRedeployConfigHandler.config.additiveCost);
server.execute(() -> {
@ -133,10 +133,10 @@ public class HardcoreRedeploy implements ModInitializer {
});
}
public static void syncRevives(MinecraftServer server, ServerPlayerEntity receiver, UUID uuid) {
public static void syncRevives(MinecraftServer server, ServerPlayer receiver, UUID uuid) {
PlayerData playerData = RedeployStateSaver.getPlayerState(server, uuid);
PacketByteBuf buf = PacketByteBufs.create();
buf.writeUuid(uuid);
FriendlyByteBuf buf = PacketByteBufs.create();
buf.writeUUID(uuid);
buf.writeInt(playerData.timesRevived);
server.execute(() -> {
ServerPlayNetworking.send(receiver, SEND_REVIVES_UPDATE, buf);

View File

@ -4,7 +4,7 @@ import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.touhoudiscord.HardcoreRedeployConfigHandler.HardcoreRedeployConfig;
import net.touhoudiscord.block.client.BuyStationRenderer;
import net.touhoudiscord.screen.RedeployingScreen;
@ -20,10 +20,10 @@ public class HardcoreRedeployClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
BlockEntityRendererFactories.register(HardcoreRedeploy.BUY_STATION_ENTITY, BuyStationRenderer::new);
BlockEntityRenderers.register(HardcoreRedeploy.BUY_STATION_ENTITY, BuyStationRenderer::new);
ClientPlayNetworking.registerGlobalReceiver(HardcoreRedeploy.SEND_REVIVES_UPDATE, (client, handler, buf, responseSender) -> {
UUID uuid = buf.readUuid();
UUID uuid = buf.readUUID();
int revives = buf.readInt();
client.execute(() -> {
reviveMap.put(uuid, revives);

View File

@ -1,20 +1,20 @@
package net.touhoudiscord;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.world.GameMode;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.level.GameType;
public class RedeployPlayer {
public static void redeploy(ServerPlayerEntity spectator, ServerPlayerEntity target) {
if (!(spectator.interactionManager.getGameMode() == GameMode.SPECTATOR)) return;
public static void redeploy(ServerPlayer spectator, ServerPlayer target) {
if (!(spectator.gameMode.getGameModeForPlayer() == GameType.SPECTATOR)) return;
if (!target.getServerWorld().getDimension().hasCeiling()) spectator.addStatusEffect(new StatusEffectInstance(HardcoreRedeploy.REDEPLOYING, 20*20, 0));
spectator.teleport(target.getServerWorld(), target.getPos().x, target.getServerWorld().getDimension().hasCeiling() ? target.getPos().y : 320, target.getPos().z, 0, 30);
spectator.changeGameMode(GameMode.SURVIVAL);
if (!target.serverLevel().dimensionType().hasCeiling()) spectator.addEffect(new MobEffectInstance(HardcoreRedeploy.REDEPLOYING, 20*20, 0));
spectator.teleportTo(target.serverLevel(), target.position().x, target.serverLevel().dimensionType().hasCeiling() ? target.position().y : 320, target.position().z, 0, 30);
spectator.setGameMode(GameType.SURVIVAL);
RedeployStateSaver.getPlayerState(spectator).timesRevived++;
spectator.server.getPlayerManager().getPlayerList().forEach(player -> {
HardcoreRedeploy.syncRevives(player.server, player, spectator.getUuid());
spectator.server.getPlayerList().getPlayers().forEach(player -> {
HardcoreRedeploy.syncRevives(player.server, player, spectator.getUUID());
});
}
}

View File

@ -1,25 +1,24 @@
package net.touhoudiscord;
import net.minecraft.entity.LivingEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.PersistentState;
import net.minecraft.world.PersistentStateManager;
import net.minecraft.world.World;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.saveddata.SavedData;
import net.minecraft.world.level.storage.DimensionDataStorage;
import java.util.HashMap;
import java.util.UUID;
public class RedeployStateSaver extends PersistentState {
public class RedeployStateSaver extends SavedData {
public HashMap<UUID, PlayerData> players = new HashMap<>();
@Override
public NbtCompound writeNbt(NbtCompound nbt) {
public CompoundTag save(CompoundTag nbt) {
NbtCompound playersNbt = new NbtCompound();
CompoundTag playersNbt = new CompoundTag();
players.forEach((uuid, playerData) -> {
NbtCompound playerNbt = new NbtCompound();
CompoundTag playerNbt = new CompoundTag();
playerNbt.putInt("timesRevived", playerData.timesRevived);
@ -30,11 +29,11 @@ public class RedeployStateSaver extends PersistentState {
return nbt;
}
public static RedeployStateSaver createFromNbt(NbtCompound tag) {
public static RedeployStateSaver createFromNbt(CompoundTag tag) {
RedeployStateSaver state = new RedeployStateSaver();
NbtCompound playersNbt = tag.getCompound("players");
playersNbt.getKeys().forEach(key -> {
CompoundTag playersNbt = tag.getCompound("players");
playersNbt.getAllKeys().forEach(key -> {
PlayerData playerData = new PlayerData();
playerData.timesRevived = playersNbt.getCompound(key).getInt("timesRevived");
@ -47,19 +46,19 @@ public class RedeployStateSaver extends PersistentState {
}
public static RedeployStateSaver getServerState(MinecraftServer server) {
PersistentStateManager persistentStateManager = server.getWorld(World.OVERWORLD).getPersistentStateManager();
DimensionDataStorage persistentStateManager = server.getLevel(Level.OVERWORLD).getDataStorage();
RedeployStateSaver state = persistentStateManager.getOrCreate(RedeployStateSaver::createFromNbt, RedeployStateSaver::new, HardcoreRedeploy.MOD_ID);
RedeployStateSaver state = persistentStateManager.computeIfAbsent(RedeployStateSaver::createFromNbt, RedeployStateSaver::new, HardcoreRedeploy.MOD_ID);
state.markDirty();
state.setDirty();
return state;
}
public static PlayerData getPlayerState(LivingEntity player) {
RedeployStateSaver serverState = getServerState(player.getWorld().getServer());
RedeployStateSaver serverState = getServerState(player.level().getServer());
PlayerData playerState = serverState.players.computeIfAbsent(player.getUuid(), uuid -> new PlayerData());
PlayerData playerState = serverState.players.computeIfAbsent(player.getUUID(), uuid -> new PlayerData());
return playerState;
}

View File

@ -1,7 +1,7 @@
package net.touhoudiscord;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.level.ServerPlayer;
public interface TimerAccess {
void hardcoreredeploy_redeployInTicks(ServerPlayerEntity spectator, ServerPlayerEntity target, Long ticks);
void hardcoreredeploy_redeployInTicks(ServerPlayer spectator, ServerPlayer target, Long ticks);
}

View File

@ -1,87 +1,93 @@
package net.touhoudiscord.block;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.StringIdentifiable;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldEvents;
import net.minecraft.world.WorldView;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.LevelEvent;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.touhoudiscord.BuyStationCapable;
import org.jetbrains.annotations.Nullable;
public class BuyStation extends BlockWithEntity {
public static final EnumProperty<BuyStationPart> BUY_STATION_PART = EnumProperty.of("part", BuyStationPart.class);
public class BuyStation extends BaseEntityBlock {
public static final EnumProperty<BuyStationPart> BUY_STATION_PART = EnumProperty.create("part", BuyStationPart.class);
protected static final VoxelShape NORTH_SHAPE = Block.createCuboidShape(1.0, 0.0, 1.0, 16.0, 12.0, 15.0);
protected static final VoxelShape SOUTH_SHAPE = Block.createCuboidShape(0.0, 0.0, 1.0, 15.0, 12.0, 15.0);
protected static final VoxelShape WEST_SHAPE = Block.createCuboidShape(1.0, 0.0, 0.0, 15.0, 12.0, 15.0);
protected static final VoxelShape EAST_SHAPE = Block.createCuboidShape(1.0, 0.0, 1.0, 15.0, 12.0, 16.0);
protected static final VoxelShape NORTH_SHAPE = Block.box(1.0, 0.0, 1.0, 16.0, 12.0, 15.0);
protected static final VoxelShape SOUTH_SHAPE = Block.box(0.0, 0.0, 1.0, 15.0, 12.0, 15.0);
protected static final VoxelShape WEST_SHAPE = Block.box(1.0, 0.0, 0.0, 15.0, 12.0, 15.0);
protected static final VoxelShape EAST_SHAPE = Block.box(1.0, 0.0, 1.0, 15.0, 12.0, 16.0);
public BuyStation(Settings settings) {
public BuyStation(Properties settings) {
super(settings);
this.setDefaultState(this.getDefaultState()
.with(HorizontalFacingBlock.FACING, Direction.NORTH)
.with(BUY_STATION_PART, BuyStationPart.MAIN));
this.registerDefaultState(this.defaultBlockState()
.setValue(HorizontalDirectionalBlock.FACING, Direction.NORTH)
.setValue(BUY_STATION_PART, BuyStationPart.MAIN));
}
@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return this.getDefaultState().with(HorizontalFacingBlock.FACING, ctx.getHorizontalPlayerFacing());
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
return this.defaultBlockState().setValue(HorizontalDirectionalBlock.FACING, ctx.getHorizontalDirection());
}
@Override
public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) {
super.onPlaced(world, pos, state, placer, itemStack);
if (!world.isClient) {
BlockPos blockPos = pos.offset(state.get(HorizontalFacingBlock.FACING).rotateYClockwise());
world.setBlockState(blockPos, state.with(BUY_STATION_PART, BuyStationPart.AUX), Block.NOTIFY_ALL);
world.updateNeighbors(pos, Blocks.AIR);
state.updateNeighbors(world, pos, Block.NOTIFY_ALL);
public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) {
super.setPlacedBy(world, pos, state, placer, itemStack);
if (!world.isClientSide) {
BlockPos blockPos = pos.relative(state.getValue(HorizontalDirectionalBlock.FACING).getClockWise());
world.setBlock(blockPos, state.setValue(BUY_STATION_PART, BuyStationPart.AUX), Block.UPDATE_ALL);
world.blockUpdated(pos, Blocks.AIR);
state.updateNeighbourShapes(world, pos, Block.UPDATE_ALL);
}
}
@Override
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
if (world.isClient()) {
super.onBreak(world, pos, state, player);
public void playerWillDestroy(Level world, BlockPos pos, BlockState state, Player player) {
if (world.isClientSide()) {
super.playerWillDestroy(world, pos, state, player);
}
BuyStationPart part = state.get(BUY_STATION_PART);
BuyStationPart part = state.getValue(BUY_STATION_PART);
if (part == BuyStationPart.MAIN) {
BlockPos otherpos = pos.offset(state.get(HorizontalFacingBlock.FACING).rotateYClockwise());
BlockPos otherpos = pos.relative(state.getValue(HorizontalDirectionalBlock.FACING).getClockWise());
BlockState otherstate = world.getBlockState(otherpos);
if (otherstate.getBlock() == this) {
world.setBlockState(otherpos, Blocks.AIR.getDefaultState(), Block.NOTIFY_ALL);
world.syncWorldEvent(player, WorldEvents.BLOCK_BROKEN, otherpos, Block.getRawIdFromState(otherstate));
world.setBlock(otherpos, Blocks.AIR.defaultBlockState(), Block.UPDATE_ALL);
world.levelEvent(player, LevelEvent.PARTICLES_DESTROY_BLOCK, otherpos, Block.getId(otherstate));
}
}
else if (part == BuyStationPart.AUX) {
BlockPos otherpos = pos.offset(state.get(HorizontalFacingBlock.FACING).rotateYCounterclockwise());
BlockPos otherpos = pos.relative(state.getValue(HorizontalDirectionalBlock.FACING).getCounterClockWise());
BlockState otherstate = world.getBlockState(otherpos);
if (otherstate.getBlock() == this) {
world.setBlockState(otherpos, Blocks.AIR.getDefaultState(), Block.NOTIFY_ALL);
world.syncWorldEvent(player, WorldEvents.BLOCK_BROKEN, otherpos, Block.getRawIdFromState(otherstate));
world.setBlock(otherpos, Blocks.AIR.defaultBlockState(), Block.UPDATE_ALL);
world.levelEvent(player, LevelEvent.PARTICLES_DESTROY_BLOCK, otherpos, Block.getId(otherstate));
}
}
}
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
Direction direction = state.get(HorizontalFacingBlock.FACING);
BuyStationPart part = state.get(BUY_STATION_PART);
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
Direction direction = state.getValue(HorizontalDirectionalBlock.FACING);
BuyStationPart part = state.getValue(BUY_STATION_PART);
if (part == BuyStationPart.AUX) direction = direction.getOpposite();
return switch (direction) {
default -> NORTH_SHAPE;
@ -92,38 +98,38 @@ public class BuyStation extends BlockWithEntity {
}
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
Block block = world.getBlockState(pos).getBlock();
if (block instanceof BuyStation) {
((BuyStationCapable) player).hardcoreredeploy_openBuyStationScreen(pos);
return ActionResult.success(world.isClient);
return InteractionResult.sidedSuccess(world.isClientSide);
} else {
return ActionResult.PASS;
return InteractionResult.PASS;
}
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(HorizontalFacingBlock.FACING, BUY_STATION_PART);
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(HorizontalDirectionalBlock.FACING, BUY_STATION_PART);
}
@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return state.get(BUY_STATION_PART) == BuyStationPart.MAIN ? new BuyStationEntity(pos, state) : null;
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return state.getValue(BUY_STATION_PART) == BuyStationPart.MAIN ? new BuyStationEntity(pos, state) : null;
}
@Override
public BlockRenderType getRenderType(BlockState state) {
return state.get(BUY_STATION_PART) == BuyStationPart.MAIN ? BlockRenderType.MODEL : BlockRenderType.INVISIBLE;
public RenderShape getRenderShape(BlockState state) {
return state.getValue(BUY_STATION_PART) == BuyStationPart.MAIN ? RenderShape.MODEL : RenderShape.INVISIBLE;
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
return world.getBlockState(pos.offset(state.get(HorizontalFacingBlock.FACING).rotateYClockwise())).isReplaceable() && super.canPlaceAt(state, world, pos);
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
return world.getBlockState(pos.relative(state.getValue(HorizontalDirectionalBlock.FACING).getClockWise())).canBeReplaced() && super.canSurvive(state, world, pos);
}
public enum BuyStationPart implements StringIdentifiable {
public enum BuyStationPart implements StringRepresentable {
MAIN("main"),
AUX("aux");
@ -137,7 +143,7 @@ public class BuyStation extends BlockWithEntity {
return this.name;
}
public String asString() {
public String getSerializedName() {
return this.name;
}
}

View File

@ -1,11 +1,11 @@
package net.touhoudiscord.block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import net.touhoudiscord.HardcoreRedeploy;
import software.bernie.geckolib.animatable.GeoBlockEntity;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
@ -29,8 +29,8 @@ public class BuyStationEntity extends BlockEntity implements GeoBlockEntity {
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
controllers.add(new AnimationController<>(this, "buystationcontroller", 0, state -> {
Vec3d pos = state.getAnimatable().getPos().toCenterPos();
if (state.getAnimatable().getWorld().getClosestPlayer(pos.x, pos.y, pos.z, 5, false) instanceof PlayerEntity) {
Vec3 pos = state.getAnimatable().getBlockPos().getCenter();
if (state.getAnimatable().getLevel().getNearestPlayer(pos.x, pos.y, pos.z, 5, false) instanceof Player) {
return state.setAndContinue(OPEN);
}
else {
@ -38,10 +38,10 @@ public class BuyStationEntity extends BlockEntity implements GeoBlockEntity {
}
})
.setSoundKeyframeHandler(event -> {
PlayerEntity player = ClientUtils.getClientPlayer();
Player player = ClientUtils.getClientPlayer();
if (player != null) {
player.getWorld().playSound(player, this.getPos(), HardcoreRedeploy.BUY_STATION_SOUND_EVENT, SoundCategory.BLOCKS, 1, 1);
player.level().playSound(player, this.getBlockPos(), HardcoreRedeploy.BUY_STATION_SOUND_EVENT, SoundSource.BLOCKS, 1, 1);
}
}));
}

View File

@ -2,7 +2,7 @@ package net.touhoudiscord.block.client;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.util.Identifier;
import net.minecraft.resources.ResourceLocation;
import net.touhoudiscord.HardcoreRedeploy;
import net.touhoudiscord.block.BuyStationEntity;
import software.bernie.geckolib.model.GeoModel;
@ -10,17 +10,17 @@ import software.bernie.geckolib.model.GeoModel;
@Environment(EnvType.CLIENT)
public class BuyStationModel extends GeoModel<BuyStationEntity> {
@Override
public Identifier getModelResource(BuyStationEntity animatable) {
return new Identifier(HardcoreRedeploy.MOD_ID, "geo/buy_station.geo.json");
public ResourceLocation getModelResource(BuyStationEntity animatable) {
return new ResourceLocation(HardcoreRedeploy.MOD_ID, "geo/buy_station.geo.json");
}
@Override
public Identifier getTextureResource(BuyStationEntity animatable) {
return new Identifier(HardcoreRedeploy.MOD_ID, "textures/block/buy_station.png");
public ResourceLocation getTextureResource(BuyStationEntity animatable) {
return new ResourceLocation(HardcoreRedeploy.MOD_ID, "textures/block/buy_station.png");
}
@Override
public Identifier getAnimationResource(BuyStationEntity animatable) {
return new Identifier(HardcoreRedeploy.MOD_ID, "animations/buy_station.animation.json");
public ResourceLocation getAnimationResource(BuyStationEntity animatable) {
return new ResourceLocation(HardcoreRedeploy.MOD_ID, "animations/buy_station.animation.json");
}
}

View File

@ -1,27 +1,27 @@
package net.touhoudiscord.block.client;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.HorizontalFacingBlock;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.Direction;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.touhoudiscord.block.BuyStationEntity;
import software.bernie.geckolib.cache.object.BakedGeoModel;
import software.bernie.geckolib.renderer.GeoBlockRenderer;
@Environment(EnvType.CLIENT)
public class BuyStationRenderer extends GeoBlockRenderer<BuyStationEntity> {
public BuyStationRenderer(BlockEntityRendererFactory.Context context) {
public BuyStationRenderer(BlockEntityRendererProvider.Context context) {
super(new BuyStationModel());
}
@Override
public void preRender(MatrixStack poseStack, BuyStationEntity animatable, BakedGeoModel model, VertexConsumerProvider bufferSource, VertexConsumer buffer, boolean isReRender, float partialTick, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
Direction direction = animatable.getCachedState().get(HorizontalFacingBlock.FACING).rotateYClockwise();
poseStack.translate(direction.getOffsetX()/2., 0, direction.getOffsetZ()/2.);
public void preRender(PoseStack poseStack, BuyStationEntity animatable, BakedGeoModel model, MultiBufferSource bufferSource, VertexConsumer buffer, boolean isReRender, float partialTick, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
Direction direction = animatable.getBlockState().getValue(HorizontalDirectionalBlock.FACING).getClockWise();
poseStack.translate(direction.getStepX()/2., 0, direction.getStepZ()/2.);
super.preRender(poseStack, animatable, model, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha);
}
}

View File

@ -1,28 +1,28 @@
package net.touhoudiscord.commands;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.command.CommandSource;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.world.GameMode;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.PlayerList;
import net.minecraft.world.level.GameType;
import net.touhoudiscord.RedeployPlayer;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;
public class RedeployPlayerCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(literal("redeployplayer")
.requires(source -> source.hasPermissionLevel(4))
.then(argument("player", EntityArgumentType.player())
.requires(source -> source.hasPermission(4))
.then(argument("player", EntityArgument.player())
.suggests((context, builder) -> {
PlayerManager playerManager = (context.getSource()).getServer().getPlayerManager();
return CommandSource.suggestMatching(playerManager.getPlayerList().stream().filter(
(player) -> player.interactionManager.getGameMode() == GameMode.SPECTATOR
PlayerList playerManager = (context.getSource()).getServer().getPlayerList();
return SharedSuggestionProvider.suggest(playerManager.getPlayers().stream().filter(
(player) -> player.gameMode.getGameModeForPlayer() == GameType.SPECTATOR
).map(
(player) -> player.getGameProfile().getName()
), builder);
@ -30,9 +30,9 @@ public class RedeployPlayerCommand {
.executes(context -> {
if (context.getSource().getPlayer() == null) return 0;
ServerPlayerEntity player = EntityArgumentType.getPlayer(context, "player");
ServerPlayer player = EntityArgument.getPlayer(context, "player");
RedeployPlayer.redeploy(player, context.getSource().getPlayer());
context.getSource().sendFeedback(() -> Text.literal("Redeployed ").append(player.getName()), true);
context.getSource().sendSuccess(() -> Component.literal("Redeployed ").append(player.getName()), true);
return 1;
})));

View File

@ -2,33 +2,33 @@ package net.touhoudiscord.commands;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.touhoudiscord.HardcoreRedeploy;
import net.touhoudiscord.RedeployStateSaver;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;
public class SetRevivesCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(literal("setrevives")
.requires(source -> source.hasPermissionLevel(4))
.then(argument("player", EntityArgumentType.player())
.requires(source -> source.hasPermission(4))
.then(argument("player", EntityArgument.player())
.then(argument("revives", IntegerArgumentType.integer(0))
.executes(context -> {
if (context.getSource().getPlayer() == null) return 0;
ServerPlayerEntity player = EntityArgumentType.getPlayer(context, "player");
ServerPlayer player = EntityArgument.getPlayer(context, "player");
RedeployStateSaver.getPlayerState(player).timesRevived = IntegerArgumentType.getInteger(context, "revives");
context.getSource().getServer().getPlayerManager().getPlayerList().forEach(player1 -> {
HardcoreRedeploy.syncRevives(context.getSource().getServer(), player1, player.getUuid());
context.getSource().getServer().getPlayerList().getPlayers().forEach(player1 -> {
HardcoreRedeploy.syncRevives(context.getSource().getServer(), player1, player.getUUID());
});
context.getSource().sendFeedback(() -> Text.literal("Set revives for ").append(player.getName()), true);
context.getSource().sendSuccess(() -> Component.literal("Set revives for ").append(player.getName()), true);
return 1;
}))));

View File

@ -1,8 +1,8 @@
package net.touhoudiscord.item;
import net.minecraft.block.Block;
import net.minecraft.client.render.item.BuiltinModelItemRenderer;
import net.minecraft.item.BlockItem;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.level.block.Block;
import net.touhoudiscord.item.client.BuyStationItemRenderer;
import software.bernie.geckolib.animatable.GeoItem;
import software.bernie.geckolib.animatable.SingletonGeoAnimatable;
@ -21,7 +21,7 @@ public class BuyStationItem extends BlockItem implements GeoItem {
private final AnimatableInstanceCache cache = new SingletonAnimatableInstanceCache(this);
private final Supplier<Object> renderProvider = GeoItem.makeRenderer(this);
public BuyStationItem(Block block, Settings settings) {
public BuyStationItem(Block block, Properties settings) {
super(block, settings);
SingletonGeoAnimatable.registerSyncedAnimatable(this);
}
@ -31,7 +31,7 @@ public class BuyStationItem extends BlockItem implements GeoItem {
consumer.accept(new RenderProvider() {
private final BuyStationItemRenderer renderer = new BuyStationItemRenderer();
@Override
public BuiltinModelItemRenderer getCustomRenderer() {
public BlockEntityWithoutLevelRenderer getCustomRenderer() {
return this.renderer;
}
});

View File

@ -2,7 +2,7 @@ package net.touhoudiscord.item.client;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.util.Identifier;
import net.minecraft.resources.ResourceLocation;
import net.touhoudiscord.HardcoreRedeploy;
import net.touhoudiscord.item.BuyStationItem;
import software.bernie.geckolib.model.GeoModel;
@ -10,17 +10,17 @@ import software.bernie.geckolib.model.GeoModel;
@Environment(EnvType.CLIENT)
public class BuyStationItemModel extends GeoModel<BuyStationItem> {
@Override
public Identifier getModelResource(BuyStationItem animatable) {
return new Identifier(HardcoreRedeploy.MOD_ID, "geo/buy_station.geo.json");
public ResourceLocation getModelResource(BuyStationItem animatable) {
return new ResourceLocation(HardcoreRedeploy.MOD_ID, "geo/buy_station.geo.json");
}
@Override
public Identifier getTextureResource(BuyStationItem animatable) {
return new Identifier(HardcoreRedeploy.MOD_ID, "textures/block/buy_station.png");
public ResourceLocation getTextureResource(BuyStationItem animatable) {
return new ResourceLocation(HardcoreRedeploy.MOD_ID, "textures/block/buy_station.png");
}
@Override
public Identifier getAnimationResource(BuyStationItem animatable) {
return new Identifier(HardcoreRedeploy.MOD_ID, "animations/buy_station.animation.json");
public ResourceLocation getAnimationResource(BuyStationItem animatable) {
return new ResourceLocation(HardcoreRedeploy.MOD_ID, "animations/buy_station.animation.json");
}
}

View File

@ -1,11 +1,11 @@
package net.touhoudiscord.mixin;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
import net.touhoudiscord.BuyStationCapable;
import org.spongepowered.asm.mixin.Mixin;
@Mixin(PlayerEntity.class)
@Mixin(Player.class)
public class BuyStationScreenMixin implements BuyStationCapable {
@Override
public void hardcoreredeploy_openBuyStationScreen(BlockPos blockPos) {

View File

@ -1,20 +1,20 @@
package net.touhoudiscord.mixin;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.touhoudiscord.BuyStationCapable;
import net.touhoudiscord.screen.BuyStationScreen;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(ClientPlayerEntity.class)
@Mixin(LocalPlayer.class)
public class ClientBuyStationScreenMixin implements BuyStationCapable {
@Shadow @Final protected MinecraftClient client;
@Shadow @Final protected Minecraft minecraft;
@Override
public void hardcoreredeploy_openBuyStationScreen(BlockPos blockPos) {
this.client.setScreen(new BuyStationScreen(blockPos));
this.minecraft.setScreen(new BuyStationScreen(blockPos));
}
}

View File

@ -1,8 +1,8 @@
package net.touhoudiscord.mixin;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.PlayerList;
import net.touhoudiscord.PlayerTimer;
import net.touhoudiscord.RedeployPlayer;
import net.touhoudiscord.TimerAccess;
@ -18,24 +18,24 @@ import java.util.UUID;
@Mixin(MinecraftServer.class)
public abstract class RedeployTimerMixin implements TimerAccess {
@Shadow public abstract PlayerManager getPlayerManager();
@Shadow public abstract PlayerList getPlayerList();
@Unique
private final HashMap<UUID, PlayerTimer> playerTimers = new HashMap<>();
@Inject(method = "tick", at = @At("TAIL"))
@Inject(method = "tickServer", at = @At("TAIL"))
private void onTick(CallbackInfo ci) {
this.playerTimers.forEach((uuid, timer) -> {
if (--timer.ticks == 0L) {
ServerPlayerEntity spectator = this.getPlayerManager().getPlayer(uuid);
ServerPlayerEntity target = this.getPlayerManager().getPlayer(timer.target);
ServerPlayer spectator = this.getPlayerList().getPlayer(uuid);
ServerPlayer target = this.getPlayerList().getPlayer(timer.target);
if (spectator != null && target != null) RedeployPlayer.redeploy(spectator, target);
}
});
}
@Override
public void hardcoreredeploy_redeployInTicks(ServerPlayerEntity spectator, ServerPlayerEntity target, Long ticks) {
this.playerTimers.put(spectator.getUuid(), new PlayerTimer(target.getUuid(), ticks));
public void hardcoreredeploy_redeployInTicks(ServerPlayer spectator, ServerPlayer target, Long ticks) {
this.playerTimers.put(spectator.getUUID(), new PlayerTimer(target.getUUID(), ticks));
}
}

View File

@ -1,9 +1,9 @@
package net.touhoudiscord.mixin;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.registry.tag.DamageTypeTags;
import net.minecraft.tags.DamageTypeTags;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.entity.LivingEntity;
import net.touhoudiscord.HardcoreRedeploy;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -13,10 +13,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(LivingEntity.class)
public abstract class RedeployingMixin {
@Shadow public abstract boolean hasStatusEffect(StatusEffect effect);
@Shadow public abstract boolean hasEffect(MobEffect effect);
@Inject(at = @At("HEAD"), method = "damage", cancellable = true)
@Inject(at = @At("HEAD"), method = "hurt", cancellable = true)
private void init(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
if (source.isIn(DamageTypeTags.IS_FALL) && this.hasStatusEffect(HardcoreRedeploy.REDEPLOYING)) cir.setReturnValue(false);
if (source.is(DamageTypeTags.IS_FALL) && this.hasEffect(HardcoreRedeploy.REDEPLOYING)) cir.setReturnValue(false);
}
}

View File

@ -4,17 +4,17 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.Selectable;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.ElementListWidget;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.GameMode;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.ContainerObjectSelectionList;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.narration.NarratableEntry;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.core.BlockPos;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.GameType;
import net.touhoudiscord.HardcoreRedeploy;
import net.touhoudiscord.HardcoreRedeployClient;
@ -30,46 +30,46 @@ public class BuyStationScreen extends Screen {
private PlayerListWidget playerList;
public BuyStationScreen(BlockPos blockPos) {
super(Text.literal("Buy Station"));
super(Component.literal("Buy Station"));
this.blockPos = blockPos;
}
@Override
protected void init() {
super.init();
playerList = new PlayerListWidget(client, width+38, height, height/2-58, height/2+84, 28);
client.player.networkHandler.getListedPlayerListEntries().forEach(entry -> {
if (entry.getGameMode() == GameMode.SPECTATOR) playerList.addPlayerEntry(new PlayerListEntry(Text.literal(entry.getProfile().getName()), entry.getProfile().getId()));
playerList = new PlayerListWidget(minecraft, width+38, height, height/2-58, height/2+84, 28);
minecraft.player.connection.getListedOnlinePlayers().forEach(entry -> {
if (entry.getGameMode() == GameType.SPECTATOR) playerList.addPlayerEntry(new PlayerListEntry(Component.literal(entry.getProfile().getName()), entry.getProfile().getId()));
});
addDrawableChild(playerList);
addRenderableWidget(playerList);
}
@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
public void render(GuiGraphics context, int mouseX, int mouseY, float delta) {
renderBackground(context);
context.fill(width/2-93, height/2-84, width/2+93, height/2+84, 0x8F_000000);
context.fill(width/2-93, height/2-84, width/2+93, height/2-58, 0xA0_000000);
context.getMatrices().push();
context.getMatrices().scale(1.5f, 1.5f, 1f);
context.drawText(textRenderer, Text.literal("Buy Station"), Math.round((width/2-80)/1.5f), Math.round((height/2-75)/1.5f), 0xFF_73c0e7, false);
context.getMatrices().pop();
Text money = Text.literal("$").append(Text.literal(String.valueOf(client.player.experienceLevel*100)));
context.drawText(textRenderer, money, width/2+80-textRenderer.getWidth(money), height/2-72, 0xFF_FFFFFF, false);
context.pose().pushPose();
context.pose().scale(1.5f, 1.5f, 1f);
context.drawString(font, Component.literal("Buy Station"), Math.round((width/2-80)/1.5f), Math.round((height/2-75)/1.5f), 0xFF_73c0e7, false);
context.pose().popPose();
Component money = Component.literal("$").append(Component.literal(String.valueOf(minecraft.player.experienceLevel*100)));
context.drawString(font, money, width/2+80-font.width(money), height/2-72, 0xFF_FFFFFF, false);
playerList.render(context, mouseX, mouseY, delta);
super.render(context, mouseX, mouseY, delta);
}
@Override
public boolean shouldPause() {
public boolean isPauseScreen() {
return false;
}
public class PlayerListWidget extends ElementListWidget<PlayerListEntry> {
public PlayerListWidget(MinecraftClient minecraftClient, int i, int j, int k, int l, int m) {
public class PlayerListWidget extends ContainerObjectSelectionList<PlayerListEntry> {
public PlayerListWidget(Minecraft minecraftClient, int i, int j, int k, int l, int m) {
super(minecraftClient, i, j, k, l, m);
this.setRenderBackground(false);
this.setRenderHorizontalShadows(false);
this.setRenderTopAndBottom(false);
}
public void addPlayerEntry(PlayerListEntry entry) {
@ -77,20 +77,20 @@ public class BuyStationScreen extends Screen {
}
}
public class PlayerListEntry extends ElementListWidget.Entry<PlayerListEntry> {
private final ButtonWidget button;
private final Text name;
public class PlayerListEntry extends ContainerObjectSelectionList.Entry<PlayerListEntry> {
private final Button button;
private final Component name;
private final UUID uuid;
public PlayerListEntry(Text name, UUID uuid) {
this.button = ButtonWidget.builder(name, button1 -> {
PacketByteBuf buf = PacketByteBufs.create();
buf.writeUuid(uuid);
public PlayerListEntry(Component name, UUID uuid) {
this.button = Button.builder(name, button1 -> {
FriendlyByteBuf buf = PacketByteBufs.create();
buf.writeUUID(uuid);
buf.writeBlockPos(blockPos);
ClientPlayNetworking.send(HardcoreRedeploy.REQUEST_REVIVE, buf);
client.setScreen(null);
minecraft.setScreen(null);
})
.position(4,2)
.pos(4,2)
.size(178, 18)
.build();
this.name = name;
@ -98,28 +98,28 @@ public class BuyStationScreen extends Screen {
}
@Override
public List<? extends Selectable> selectableChildren() {
public List<? extends NarratableEntry> narratables() {
return List.of(button);
}
@Override
public List<? extends Element> children() {
public List<? extends GuiEventListener> children() {
return List.of(button);
}
@Override
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
public void render(GuiGraphics context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
button.setX(x);
button.setY(y);
boolean isHovered = mouseX >= x && mouseX <= x+178 && mouseY >= y && mouseY <= y+18;
Integer revives = HardcoreRedeployClient.reviveMap.get(this.uuid);
int cost = serverConfig.baseCost+(revives == null ? 0 : revives)*serverConfig.additiveCost;
int backgroundColor = ((isHovered ? 0x30 : 0x20) << 24) +
((client.player.experienceLevel >= cost) ? 0x2397d1 : 0xa3a3a3);
((minecraft.player.experienceLevel >= cost) ? 0x2397d1 : 0xa3a3a3);
context.fill(x, y, x+178, y+18, backgroundColor);
context.drawText(textRenderer, button.getMessage(), x+4, y+5, 0xFF_73c0e7, false);
Text money = Text.literal("$").append(Text.literal(String.valueOf(cost*100)));
context.drawText(textRenderer, money, x+178-4-textRenderer.getWidth(money), y+5, 0xFF_7efc20, false);
context.drawString(font, button.getMessage(), x+4, y+5, 0xFF_73c0e7, false);
Component money = Component.literal("$").append(Component.literal(String.valueOf(cost*100)));
context.drawString(font, money, x+178-4-font.width(money), y+5, 0xFF_7efc20, false);
}
}
}

View File

@ -1,8 +1,8 @@
package net.touhoudiscord.screen;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
public class RedeployingScreen extends Screen {
@ -10,20 +10,20 @@ public class RedeployingScreen extends Screen {
private float time;
public RedeployingScreen(float duration) {
super(Text.empty());
super(Component.empty());
this.duration = duration;
}
@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
public void render(GuiGraphics context, int mouseX, int mouseY, float delta) {
time += delta;
context.fill(0, 0, width, height, Math.round((1-Math.abs((float)Math.sin(((time/(duration/2))-1)*(Math.PI/2))))*255)<<24);
super.render(context, mouseX, mouseY, delta);
if (time > duration) client.setScreen(null);
if (time > duration) minecraft.setScreen(null);
}
@Override
public boolean shouldPause() {
public boolean isPauseScreen() {
return false;
}

View File

@ -1,10 +1,10 @@
package net.touhoudiscord.status;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectCategory;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;
public class RedeployingStatusEffect extends StatusEffect {
public class RedeployingStatusEffect extends MobEffect {
public RedeployingStatusEffect() {
super(StatusEffectCategory.BENEFICIAL, 0xFFFFFF);
super(MobEffectCategory.BENEFICIAL, 0xFFFFFF);
}
}