-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move mutability to apply to spawn eggs only
- Loading branch information
1 parent
744dfe8
commit 26d3667
Showing
8 changed files
with
107 additions
and
56 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/main/java/net/modfest/fireblanket/mixin/accessor/ArmorStandEntityAccessor.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,11 @@ | ||
package net.modfest.fireblanket.mixin.accessor; | ||
|
||
import net.minecraft.entity.decoration.ArmorStandEntity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(ArmorStandEntity.class) | ||
public interface ArmorStandEntityAccessor { | ||
@Accessor | ||
void setDisabledSlots(int d); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/net/modfest/fireblanket/mixin/accessor/ItemFrameAccessor.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,11 @@ | ||
package net.modfest.fireblanket.mixin.accessor; | ||
|
||
import net.minecraft.entity.decoration.ItemFrameEntity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(ItemFrameEntity.class) | ||
public interface ItemFrameAccessor { | ||
@Accessor | ||
void setFixed(boolean v); | ||
} |
30 changes: 0 additions & 30 deletions
30
src/main/java/net/modfest/fireblanket/mixin/entity_immutability/MixinArmorStand.java
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
src/main/java/net/modfest/fireblanket/mixin/entity_immutability/MixinDecorationItem.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,23 @@ | ||
package net.modfest.fireblanket.mixin.entity_immutability; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
import net.minecraft.entity.decoration.AbstractDecorationEntity; | ||
import net.minecraft.item.DecorationItem; | ||
import net.minecraft.item.ItemUsageContext; | ||
import net.minecraft.util.ActionResult; | ||
import net.modfest.fireblanket.Fireblanket; | ||
import net.modfest.fireblanket.util.ImmutableEntities; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(DecorationItem.class) | ||
public class MixinDecorationItem { | ||
@Inject(method = "useOnBlock(Lnet/minecraft/item/ItemUsageContext;)Lnet/minecraft/util/ActionResult;", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getOrDefault(Lnet/minecraft/component/ComponentType;Ljava/lang/Object;)Ljava/lang/Object;")) | ||
private void onInitSpawnedEntity(ItemUsageContext context, CallbackInfoReturnable<ActionResult> cir, @Local AbstractDecorationEntity entity) { | ||
if (context.getWorld().getGameRules().getBoolean(Fireblanket.NEW_ENTITIES_IMMUTABLE)) { | ||
ImmutableEntities.makeImmutable(entity); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/net/modfest/fireblanket/mixin/entity_immutability/MixinEntityType.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,31 @@ | ||
package net.modfest.fireblanket.mixin.entity_immutability; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.SpawnReason; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
import net.modfest.fireblanket.Fireblanket; | ||
import net.modfest.fireblanket.util.ImmutableEntities; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
import java.util.function.Consumer; | ||
|
||
@Mixin(EntityType.class) | ||
public class MixinEntityType { | ||
@WrapOperation(method = "create(Lnet/minecraft/server/world/ServerWorld;Ljava/util/function/Consumer;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/SpawnReason;ZZ)Lnet/minecraft/entity/Entity;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityType;create(Lnet/minecraft/world/World;)Lnet/minecraft/entity/Entity;")) | ||
private Entity afterCreated(EntityType<?> instance, World world, Operation<Entity> original, ServerWorld world2, @Nullable Consumer<Entity> afterConsumer, BlockPos pos, SpawnReason reason, boolean alignPosition, boolean invertY) { | ||
var entity = original.call(instance, world); | ||
if (world.getGameRules().getBoolean(Fireblanket.NEW_ENTITIES_IMMUTABLE) && reason == SpawnReason.SPAWN_EGG) { | ||
if (entity != null) { | ||
ImmutableEntities.makeImmutable(entity); | ||
} | ||
} | ||
return entity; | ||
} | ||
} |
24 changes: 0 additions & 24 deletions
24
src/main/java/net/modfest/fireblanket/mixin/entity_immutability/MixinItemFrame.java
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
src/main/java/net/modfest/fireblanket/util/ImmutableEntities.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 net.modfest.fireblanket.util; | ||
|
||
import net.minecraft.entity.Entity; | ||
import net.modfest.fireblanket.mixin.accessor.ArmorStandEntityAccessor; | ||
import net.modfest.fireblanket.mixin.accessor.ItemFrameAccessor; | ||
import net.modfest.fireblanket.mixinsupport.ImmmovableLivingEntity; | ||
|
||
public class ImmutableEntities { | ||
public static void makeImmutable(Entity entity) { | ||
// Set invulnerability | ||
entity.setInvulnerable(true); | ||
|
||
if (entity instanceof ArmorStandEntityAccessor ae) { | ||
// Disable all slots | ||
ae.setDisabledSlots(4144959); | ||
// Disable movement (prevents abuse of fishing rods) | ||
if (entity instanceof ImmmovableLivingEntity im) { | ||
im.setNoMovement(true); | ||
} | ||
} | ||
|
||
if (entity instanceof ItemFrameAccessor ie) { | ||
// Make item frames fixed | ||
ie.setFixed(true); | ||
} | ||
} | ||
} |
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