-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from ModFest/feature/entity_modif
Allow entities to be "immutable" by default
- Loading branch information
Showing
10 changed files
with
153 additions
and
11 deletions.
There are no files selected for viewing
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
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); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/net/modfest/fireblanket/mixin/adventure_fix/MixinFarmlandBlock.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.mixin.adventure_fix; | ||
|
||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.FarmlandBlock; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
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.CallbackInfo; | ||
|
||
@Mixin(FarmlandBlock.class) | ||
public class MixinFarmlandBlock { | ||
@Inject( | ||
method = "setToDirt", | ||
at = @At("HEAD"), | ||
cancellable = true | ||
) | ||
private static void doNotSetToDirt(@Nullable Entity entity, BlockState state, World world, BlockPos pos, CallbackInfo ci) { | ||
if (entity instanceof PlayerEntity player && !player.canModifyBlocks()) { | ||
ci.cancel(); | ||
} | ||
} | ||
} |
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; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"argument.entity.selector.limit.unforced": "Targeting too many entities with no distance filter; add `force=true` to the selector to bypass", | ||
"argument.entity.options.force.description": "Force-allow more than 50 entities targeted with no distance filter" | ||
} | ||
"argument.entity.options.force.description": "Force-allow more than 50 entities targeted with no distance filter", | ||
"gamerule.newEntitiesImmutable": "Whether newly spawned entities should be immutable. (Item frames will be fixed for example" | ||
} |
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