Skip to content

Commit

Permalink
Merge pull request #14 from Dev0Louis/betterCreateChildInject
Browse files Browse the repository at this point in the history
No more Vanilla copy paste. We just use ci.getReturnValue() now :D
  • Loading branch information
nyuppo authored Nov 16, 2023
2 parents b463141 + 2acefad commit 49a1d78
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ protected void onTick(CallbackInfo ci) {

@Inject(
method = "createChild(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/entity/passive/PassiveEntity;)Lnet/minecraft/entity/passive/ChickenEntity;",
at = @At("HEAD"),
cancellable = true
at = @At("RETURN")
)
private void onCreateChild(ServerWorld world, PassiveEntity entity, CallbackInfoReturnable<ChickenEntity> ci) {
ChickenEntity child = (ChickenEntity)EntityType.CHICKEN.create(world);
ChickenEntity child = ci.getReturnValue();

MobVariant variant = Variants.getChildVariant(Variants.Mob.CHICKEN, world, ((ChickenEntity)(Object)this), entity);

Expand All @@ -75,7 +74,5 @@ private void onCreateChild(ServerWorld world, PassiveEntity entity, CallbackInfo
child.writeNbt(childNbt);
childNbt.putString("Variant", variant.getIdentifier().toString());
child.readCustomDataFromNbt(childNbt);

ci.setReturnValue(child);
}
}
7 changes: 2 additions & 5 deletions src/main/java/com/github/nyuppo/mixin/CowVariantsMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ protected void onTick(CallbackInfo ci) {

@Inject(
method = "createChild(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/entity/passive/PassiveEntity;)Lnet/minecraft/entity/passive/CowEntity;",
at = @At("HEAD"),
cancellable = true
at = @At("RETURN")
)
private void onCreateChild(ServerWorld world, PassiveEntity entity, CallbackInfoReturnable<CowEntity> ci) {
CowEntity child = (CowEntity)EntityType.COW.create(world);
CowEntity child = ci.getReturnValue();

MobVariant variant = Variants.getChildVariant(Variants.Mob.COW, world, ((CowEntity)(Object)this), entity);

Expand All @@ -74,7 +73,5 @@ private void onCreateChild(ServerWorld world, PassiveEntity entity, CallbackInfo
child.writeNbt(childNbt);
childNbt.putString("Variant", variant.getIdentifier().toString());
child.readCustomDataFromNbt(childNbt);

ci.setReturnValue(child);
}
}
7 changes: 2 additions & 5 deletions src/main/java/com/github/nyuppo/mixin/PigVariantsMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,10 @@ protected void onTick(CallbackInfo ci) {

@Inject(
method = "createChild(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/entity/passive/PassiveEntity;)Lnet/minecraft/entity/passive/PigEntity;",
at = @At("HEAD"),
cancellable = true
at = @At("RETURN")
)
private void onCreateChild(ServerWorld world, PassiveEntity entity, CallbackInfoReturnable<PigEntity> ci) {
PigEntity child = (PigEntity)EntityType.PIG.create(world);
PigEntity child = ci.getReturnValue();

MobVariant variant = Variants.getChildVariant(Variants.Mob.PIG, world, ((PigEntity)(Object)this), entity);

Expand All @@ -114,7 +113,5 @@ private void onCreateChild(ServerWorld world, PassiveEntity entity, CallbackInfo
child.writeNbt(childNbt);
childNbt.putString("Variant", variant.getIdentifier().toString());
child.readCustomDataFromNbt(childNbt);

ci.setReturnValue(child);
}
}
10 changes: 2 additions & 8 deletions src/main/java/com/github/nyuppo/mixin/SheepVariantsMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,10 @@ protected void onTick(CallbackInfo ci) {

@Inject(
method = "createChild(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/entity/passive/PassiveEntity;)Lnet/minecraft/entity/passive/SheepEntity;",
at = @At("HEAD"),
cancellable = true
at = @At("RETURN")
)
private void onCreateChild(ServerWorld world, PassiveEntity entity, CallbackInfoReturnable<SheepEntity> ci) {
SheepEntity child = (SheepEntity)EntityType.SHEEP.create(world);
if (child != null) {
child.setColor(this.getChildColor(((SheepEntity)(Object)this), (SheepEntity)entity));
}
SheepEntity child = ci.getReturnValue();

MobVariant variant = Variants.getChildVariant(Variants.Mob.SHEEP, world, ((SheepEntity)(Object)this), entity);

Expand All @@ -84,7 +80,5 @@ private void onCreateChild(ServerWorld world, PassiveEntity entity, CallbackInfo
child.writeNbt(childNbt);
childNbt.putString("Variant", variant.getIdentifier().toString());
child.readCustomDataFromNbt(childNbt);

ci.setReturnValue(child);
}
}
14 changes: 2 additions & 12 deletions src/main/java/com/github/nyuppo/mixin/WolfVariantsMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,10 @@ protected void onTick(CallbackInfo ci) {

@Inject(
method = "createChild(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/entity/passive/PassiveEntity;)Lnet/minecraft/entity/passive/WolfEntity;",
at = @At("HEAD"),
cancellable = true
at = @At("RETURN")
)
private void onCreateChild(ServerWorld world, PassiveEntity entity, CallbackInfoReturnable<WolfEntity> ci) {
WolfEntity child = (WolfEntity) EntityType.WOLF.create(world);
if (child != null) {
UUID uUID = ((WolfEntity)(Object)this).getOwnerUuid();
if (uUID != null) {
child.setOwnerUuid(uUID);
child.setTamed(true);
}
}
WolfEntity child = ci.getReturnValue();

MobVariant variant = Variants.getChildVariant(Variants.Mob.WOLF, world, ((WolfEntity)(Object)this), entity);

Expand All @@ -84,7 +76,5 @@ private void onCreateChild(ServerWorld world, PassiveEntity entity, CallbackInfo
child.writeNbt(childNbt);
childNbt.putString("Variant", variant.getIdentifier().toString());
child.readCustomDataFromNbt(childNbt);

ci.setReturnValue(child);
}
}

0 comments on commit 49a1d78

Please sign in to comment.