-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Status Effect and Potion Support (#4)
* Status Effect and Potion Support Adds support for virtual status effects and potion types. Currently no support for client screen/HUD element rendering (currently nothing renders in both cases) * Fix TestMod status effect and add client display support - Fixed the status effect in the test mod - Added support for sending a vanilla status effect to the client (for display in the HUD/Inventory screen). This defaults to nothing being sent to the client
- Loading branch information
Showing
9 changed files
with
134 additions
and
7 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/main/java/eu/pb4/polymer/interfaces/VirtualStatusEffect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package eu.pb4.polymer.interfaces; | ||
|
||
import net.minecraft.entity.effect.StatusEffect; | ||
|
||
public interface VirtualStatusEffect extends VirtualObject { | ||
|
||
/** | ||
* Returns the effect to be displayed on the client's HUD. | ||
* Note that particle color is determined by the server, so this will not affect them. | ||
* | ||
* @return Vanilla status effect, or <code>null</>null if nothing is to be displayed by the client | ||
*/ | ||
default StatusEffect getVirtualStatusEffect() { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/eu/pb4/polymer/mixin/other/EntityStatusEffectS2CPacketMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package eu.pb4.polymer.mixin.other; | ||
|
||
import eu.pb4.polymer.interfaces.VirtualStatusEffect; | ||
import net.minecraft.entity.effect.StatusEffect; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.network.packet.s2c.play.EntityStatusEffectS2CPacket; | ||
import net.minecraft.util.registry.Registry; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Mutable; | ||
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; | ||
|
||
@Mixin(EntityStatusEffectS2CPacket.class) | ||
public class EntityStatusEffectS2CPacketMixin { | ||
|
||
@Mutable @Shadow @Final private byte effectId; | ||
|
||
@Inject(method = "write", at = @At("HEAD")) | ||
public void polymer_onWrite(PacketByteBuf buf, CallbackInfo callbackInfo) { | ||
if (Registry.STATUS_EFFECT.get(this.effectId) instanceof VirtualStatusEffect virtualEffect && virtualEffect.getVirtualStatusEffect() != null) { | ||
this.effectId = (byte) (StatusEffect.getRawId(virtualEffect.getVirtualStatusEffect()) & 255); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/eu/pb4/polymer/mixin/other/RemoveEntityStatusEffectS2CPacketMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package eu.pb4.polymer.mixin.other; | ||
|
||
import eu.pb4.polymer.interfaces.VirtualStatusEffect; | ||
import net.minecraft.entity.effect.StatusEffect; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.network.packet.s2c.play.RemoveEntityStatusEffectS2CPacket; | ||
import net.minecraft.util.registry.Registry; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Mutable; | ||
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; | ||
|
||
@Mixin(RemoveEntityStatusEffectS2CPacket.class) | ||
public class RemoveEntityStatusEffectS2CPacketMixin { | ||
|
||
@Mutable @Shadow @Final private StatusEffect effectType; | ||
|
||
@Inject(method = "write", at = @At("HEAD")) | ||
public void polymer_onWrite(PacketByteBuf buf, CallbackInfo callbackInfo) { | ||
if (effectType instanceof VirtualStatusEffect virtualEffect && virtualEffect.getVirtualStatusEffect() != null) { | ||
this.effectType = ((VirtualStatusEffect) effectType).getVirtualStatusEffect(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package eu.pb4.polymertest; | ||
|
||
import eu.pb4.polymer.interfaces.VirtualObject; | ||
import eu.pb4.polymer.interfaces.VirtualStatusEffect; | ||
import net.minecraft.entity.EquipmentSlot; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.effect.StatusEffect; | ||
import net.minecraft.entity.effect.StatusEffectCategory; | ||
import net.minecraft.entity.effect.StatusEffects; | ||
|
||
public class TestStatusEffect extends StatusEffect implements VirtualStatusEffect { | ||
protected TestStatusEffect() { | ||
super(StatusEffectCategory.BENEFICIAL, 110011); | ||
} | ||
|
||
@Override | ||
public void applyUpdateEffect(LivingEntity entity, int amplifier) { | ||
if (entity.getMainHandStack().isDamageable()) { | ||
entity.getMainHandStack().damage(amplifier + 1, entity, entity1 -> entity1.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND)); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean canApplyUpdateEffect(int duration, int amplifier) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public StatusEffect getVirtualStatusEffect() { | ||
return StatusEffects.CONDUIT_POWER; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
{ | ||
"block.test.potato_block": "Tiny Potato", | ||
"enchantment.test.enchantment": "TestEnch" | ||
"enchantment.test.enchantment": "TestEnch", | ||
"item.minecraft.potion.effect.potion": "TestPot", | ||
"effect.test.effect": "Test Effect" | ||
|
||
} |