Compare commits

...

3 commits

Author SHA1 Message Date
5af7393908
change: don't allow knocked players to place blocks
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
2024-07-18 15:32:20 +05:00
e2021309cc
change: display callout and notifs for longer
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
2024-07-18 14:05:08 +05:00
ffe591aa39
change: reduce communication gui size above scale factor 3
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
2024-07-18 14:04:55 +05:00
13 changed files with 88 additions and 31 deletions

View file

@ -11,7 +11,6 @@ import ru.octol1ttle.knockdowns.client.communication.KnockedNotificationManager;
import ru.octol1ttle.knockdowns.client.event.KnockdownsKeyListener;
import ru.octol1ttle.knockdowns.client.util.DirectionalCallSound;
import ru.octol1ttle.knockdowns.common.IClientProxy;
import ru.octol1ttle.knockdowns.common.KnockdownsMod;
import ru.octol1ttle.knockdowns.common.data.IKnockdownsPlayerData;
import ru.octol1ttle.knockdowns.common.network.packets.s2c.PlayerCalloutS2CPacket;
import ru.octol1ttle.knockdowns.common.network.packets.s2c.PlayerKnockedDownS2CPacket;
@ -27,7 +26,6 @@ public class ClientProxy implements IClientProxy {
@Override
public void onFMLInit(FMLInitializationEvent event) {
KnockdownsMod.LOGGER.info("Registering key bindings");
KnockdownsKeyListener.registerKeyBindings();
}

View file

@ -39,8 +39,8 @@ public class KnockdownsClientEventListener {
KnockedNotificationManager.clearDatas();
return;
}
CalloutManager.getCallouts().removeIf(callout -> client.world.getTotalWorldTime() - callout.getValue().getReceiveTime() > 60);
KnockedNotificationManager.getKnockedPlayerDatas().removeIf(notification -> client.world.getTotalWorldTime() - notification.getReceiveTime() > 100);
CalloutManager.getCallouts().removeIf(callout -> client.world.getTotalWorldTime() - callout.getValue().getReceiveTime() > 100);
KnockedNotificationManager.getKnockedPlayerDatas().removeIf(notification -> client.world.getTotalWorldTime() - notification.getReceiveTime() > 140);
}
@SubscribeEvent

View file

@ -34,10 +34,16 @@ public class CommunicationGui extends KnockdownsBaseGui {
@Override
public void render(float partialTicks, ScaledResolution resolution) {
GlStateManager.pushMatrix();
float scale = 1.0f;
if (resolution.getScaleFactor() > 3) {
scale = (float) 3 / resolution.getScaleFactor();
GlStateManager.scale(scale, scale, 1.0f);
}
FontRenderer font = client.fontRenderer;
int x = SCREEN_EDGE_MARGIN;
int y = resolution.getScaledHeight() - SCREEN_EDGE_MARGIN - font.FONT_HEIGHT;
int y = (int) (resolution.getScaledHeight() / scale - SCREEN_EDGE_MARGIN - font.FONT_HEIGHT);
KeyBinding[] sortedBindings = new KeyBinding[4];
for (KeyBinding binding : KnockdownsKeyListener.calloutBindings.keySet())
@ -135,6 +141,8 @@ public class CommunicationGui extends KnockdownsBaseGui {
KEY_SIZE
);
}
GlStateManager.popMatrix();
}
public void renderCallouts(float partialTicks) {

View file

@ -30,7 +30,7 @@ public class ReviveGui extends KnockdownsBaseGui {
String timerText = String.format("%.1f", data.getReviveTimeLeft() / 20.0f);
float timerX = (resolution.getScaledWidth() - font.getStringWidth(timerText)) * 0.5f;
data.getRevivers().removeIf(reviver -> reviver.isDead || !reviver.isEntityAlive() || IKnockdownsPlayerData.get(reviver).isKnockedDown());
data.getRevivers().removeIf(reviver -> !reviver.isEntityAlive() || IKnockdownsPlayerData.get(reviver).isKnockedDown());
int reviverCount = data.getRevivers().size();
TextFormatting color;
if (reviverCount == 0) {

View file

@ -0,0 +1,16 @@
package ru.octol1ttle.knockdowns.client.mixin;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import ru.octol1ttle.knockdowns.common.data.IKnockdownsPlayerData;
@Mixin(PlayerControllerMP.class)
public abstract class PlayerControllerMPMixin {
@ModifyExpressionValue(method = "processRightClickBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemBlock;canPlaceBlockOnSide(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/EnumFacing;Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/item/ItemStack;)Z"))
private boolean cancelPlaceIfKnockedDown(boolean original) {
return original && !IKnockdownsPlayerData.get(Minecraft.getMinecraft().player).isKnockedDown();
}
}

View file

@ -45,15 +45,14 @@ import static ru.octol1ttle.knockdowns.common.KnockdownsUtils.resetKnockedState;
@Mod.EventBusSubscriber(modid = Tags.MOD_ID)
public class KnockdownsCommonEventListener {
public static void onFMLInit(FMLInitializationEvent event) {
KnockdownsMod.LOGGER.info("Registering network packets");
KnockdownsNetwork.registerPackets();
KnockdownsMod.LOGGER.info("Registering capability");
KnockdownsCapability.register();
}
@SubscribeEvent
public static void onSoundsRegister(RegistryEvent.Register<SoundEvent> event) {
event.getRegistry().register(KnockdownsSoundEvents.CALLOUT);
event.getRegistry().register(KnockdownsSoundEvents.KNOCKED_DOWN);
}
@SubscribeEvent
@ -63,6 +62,15 @@ public class KnockdownsCommonEventListener {
}
}
@SubscribeEvent
public static void onPlayerJoin(PlayerLoggedInEvent event) {
IKnockdownsPlayerData data = IKnockdownsPlayerData.get(event.player);
KnockdownsNetwork.sendToPlayer(
new SynchronizePlayerDataS2CPacket.Full(event.player.getEntityId(), data.isKnockedDown(), data.getReviveTimeLeft()),
(EntityPlayerMP) event.player
);
}
@SubscribeEvent
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
MinecraftServer server = event.player.getServer();
@ -75,13 +83,15 @@ public class KnockdownsCommonEventListener {
return;
}
knocked.clearElytraFlying();
if (allPlayersKnocked(server, knocked)) {
knocked.attackEntityFrom(DamageSource.GENERIC, knocked.getMaxHealth());
return;
}
List<EntityPlayer> revivers = data.getRevivers();
revivers.removeIf(reviver -> reviver.isDead || !reviver.isEntityAlive() || IKnockdownsPlayerData.get(reviver).isKnockedDown());
revivers.removeIf(reviver -> !reviver.isEntityAlive() || IKnockdownsPlayerData.get(reviver).isKnockedDown());
if (!revivers.isEmpty()) {
data.setReviveTimeLeft(data.getReviveTimeLeft() - revivers.size());
KnockdownsNetwork.sendToMultiple(
@ -112,7 +122,13 @@ public class KnockdownsCommonEventListener {
data.setTicksKnocked(data.getTicksKnocked() + 1);
int period = MathHelper.floor(KNOCKED_HURT_PERIOD * 20);
if (data.getTicksKnocked() >= KNOCKED_INVULNERABILITY_TICKS && data.getTicksKnocked() % period == 0) {
if (data.getTicksKnocked() <= KNOCKED_INVULNERABILITY_TICKS) {
knocked.setEntityInvulnerable(true);
knocked.extinguish();
knocked.setAir(300);
KnockdownsUtils.clearBadPotionEffects(knocked);
knocked.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, Integer.MAX_VALUE, 3));
} else if (data.getTicksKnocked() % period == 0) {
knocked.setEntityInvulnerable(false);
knocked.attackEntityFrom(DamageSource.GENERIC, knocked.getMaxHealth() / (KNOCKED_TENACITY / KNOCKED_HURT_PERIOD));
}
@ -131,19 +147,17 @@ public class KnockdownsCommonEventListener {
}
if (data.isKnockedDown() || allPlayersKnocked(player.getServer(), player)) {
data.getRevivers().clear();
return;
}
player.clearActivePotions();
player.setEntityInvulnerable(true);
player.setHealth(1.0f);
player.setAbsorptionAmount(player.getMaxHealth() - 1.0f);
player.extinguish();
player.setAir(300);
player.clearElytraFlying();
player.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 6000, 3));
KnockdownsUtils.clearBadPotionEffects(player);
player.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, Integer.MAX_VALUE, 3));
Entity trueSource = event.getSource().getTrueSource();
if (trueSource instanceof EntityLiving) {
@ -232,15 +246,6 @@ public class KnockdownsCommonEventListener {
}
}
@SubscribeEvent
public static void onPlayerJoin(PlayerLoggedInEvent event) {
IKnockdownsPlayerData data = IKnockdownsPlayerData.get(event.player);
KnockdownsNetwork.sendToPlayer(
new SynchronizePlayerDataS2CPacket.Full(event.player.getEntityId(), data.isKnockedDown(), data.getReviveTimeLeft()),
(EntityPlayerMP) event.player
);
}
@SubscribeEvent
public static void onPlayerLeave(PlayerLoggedOutEvent event) {
for (EntityPlayer knocked : event.player.world.playerEntities) {

View file

@ -38,6 +38,7 @@ public class KnockdownsFMLLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixi
public List<String> getMixinConfigs() {
ArrayList<String> list = new ArrayList<>();
list.add("mixins.knockdowns.json");
list.add("mixins.knockdowns.client.json");
return list;
}
}

View file

@ -15,7 +15,6 @@ public class KnockdownsMod {
@Mod.EventHandler
public void onFMLInit(FMLInitializationEvent event) {
LOGGER.info("Initializing");
clientProxy.onFMLInit(event);
KnockdownsCommonEventListener.onFMLInit(event);
}

View file

@ -1,8 +1,12 @@
package ru.octol1ttle.knockdowns.common;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.MobEffects;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
import ru.octol1ttle.knockdowns.common.data.IKnockdownsPlayerData;
import ru.octol1ttle.knockdowns.common.network.KnockdownsNetwork;
@ -14,6 +18,20 @@ public class KnockdownsUtils {
public static final float KNOCKED_HURT_PERIOD = 1.2f;
public static final float KNOCKED_TENACITY = 60.0f;
public static void clearBadPotionEffects(EntityPlayerMP player) {
List<Potion> removeList = new ArrayList<>();
for (PotionEffect effect : player.getActivePotionEffects()) {
if (effect.getPotion().isBadEffect()) {
removeList.add(effect.getPotion());
}
}
for (Potion potion : removeList) {
player.removePotionEffect(potion);
}
}
public static boolean allPlayersKnocked(MinecraftServer server, EntityPlayer except) {
for (EntityPlayer player : server.getPlayerList().getPlayers()) {
if (player.equals(except)) {
@ -32,12 +50,11 @@ public class KnockdownsUtils {
data.setKnockedDown(false);
data.setReviveTimeLeft(INITIAL_REVIVE_TIME_LEFT);
data.setTicksKnocked(0);
data.getRevivers().clear();
KnockdownsNetwork.sendToTrackingAndSelf(
new SynchronizePlayerDataS2CPacket.KnockedDown(player.getEntityId(), data.isKnockedDown()),
player
);
data.getRevivers().clear();
}
}

View file

@ -1,4 +1,4 @@
package ru.octol1ttle.knockdowns.common.mixins;
package ru.octol1ttle.knockdowns.common.mixin;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@ -19,7 +19,7 @@ public abstract class EntityLivingBaseMixin extends Entity {
}
@Inject(method = "checkTotemDeathProtection", at = @At("RETURN"))
public void onTotemActivation(CallbackInfoReturnable<Boolean> cir) {
private void onTotemActivation(CallbackInfoReturnable<Boolean> cir) {
if (cir.getReturnValue() && ((Object) this) instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP) (Object) this;
IKnockdownsPlayerData data = IKnockdownsPlayerData.get(player);

View file

@ -1,4 +1,4 @@
package ru.octol1ttle.knockdowns.common.mixins;
package ru.octol1ttle.knockdowns.common.mixin;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import net.minecraft.entity.player.EntityPlayer;
@ -8,7 +8,7 @@ import ru.octol1ttle.knockdowns.common.data.IKnockdownsPlayerData;
@SuppressWarnings("ConstantValue")
@Mixin(EntityPlayer.class)
public class EntityPlayerMixin {
public abstract class EntityPlayerMixin {
@ModifyReturnValue(method = "shouldHeal", at = @At("RETURN"))
private boolean dontHealIfKnockedDown(boolean original) {
if (((Object) this) instanceof EntityPlayer) {

View file

@ -0,0 +1,13 @@
{
"package": "ru.octol1ttle.knockdowns.client.mixin",
"required": true,
"refmap": "${mixin_refmap}",
"target": "@env(DEFAULT)",
"minVersion": "0.8.5",
"compatibilityLevel": "JAVA_8",
"mixins": [],
"server": [],
"client": [
"PlayerControllerMPMixin"
]
}

View file

@ -1,5 +1,5 @@
{
"package": "ru.octol1ttle.knockdowns.common.mixins",
"package": "ru.octol1ttle.knockdowns.common.mixin",
"required": true,
"refmap": "${mixin_refmap}",
"target": "@env(DEFAULT)",