Skip to content

Commit

Permalink
Use forge AT instead of reflection
Browse files Browse the repository at this point in the history
Resolves #9
  • Loading branch information
matshou committed Apr 22, 2020
1 parent 843421c commit 014876e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 28 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ minecraft {
mappings channel: 'snapshot', version: '20200225-1.15.1'
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.

accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')

// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/io/yooksi/cococakes/EventHandler.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package io.yooksi.cococakes;

import io.yooksi.cococakes.util.ReflectionUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
Expand All @@ -29,14 +27,8 @@ public void onBlockRightClick(PlayerInteractEvent.RightClickBlock event) {
return;
}
ItemStack stack = block.getPickBlock(state, null, world, pos, player);
java.lang.reflect.Method addItemParticles = ReflectionUtil.setMethodAccessible(
LivingEntity.class, "func_195062_a", ItemStack.class, Integer.TYPE);
try {
addItemParticles.invoke(player, stack, 2);
}
catch (IllegalAccessException | java.lang.reflect.InvocationTargetException e) {
throw new IllegalStateException(e);
}
player.addItemParticles(stack, 2);

net.minecraft.util.SoundEvent eatSound = player.getEatSound(stack);
player.playSound(eatSound, 0.15F + 0.05F * (float)RNG.nextInt(2),
(RNG.nextFloat() - RNG.nextFloat()) * 0.04F + 0.25F);
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/io/yooksi/cococakes/util/ReflectionUtil.java

This file was deleted.

1 change: 1 addition & 0 deletions src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public net.minecraft.entity.LivingEntity func_195062_a(Lnet/minecraft/item/ItemStack;I)V # addItemParticles

0 comments on commit 014876e

Please sign in to comment.