Fix server crash when using heater on a spawner
This commit is contained in:
parent
f5af1cd81e
commit
8087d7013c
1 changed files with 27 additions and 8 deletions
|
@ -1,10 +1,14 @@
|
|||
package com.simibubi.create.content.contraptions.processing;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.monster.BlazeEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
@ -16,8 +20,12 @@ import net.minecraft.tileentity.MobSpawnerTileEntity;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.WeightedSpawnerEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.spawner.AbstractSpawner;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
||||
|
||||
@MethodsReturnNonnullByDefault
|
||||
@ParametersAreNonnullByDefault
|
||||
|
@ -30,14 +38,25 @@ public class HeaterBlockItem extends BlockItem {
|
|||
public ActionResultType onItemUse(ItemUseContext context) {
|
||||
TileEntity te = context.getWorld()
|
||||
.getTileEntity(context.getPos());
|
||||
if (te instanceof MobSpawnerTileEntity && ((MobSpawnerTileEntity) te).getSpawnerBaseLogic()
|
||||
.getCachedEntity() instanceof BlazeEntity) {
|
||||
if (te instanceof MobSpawnerTileEntity) {
|
||||
AbstractSpawner spawner = ((MobSpawnerTileEntity) te).getSpawnerBaseLogic();
|
||||
List<WeightedSpawnerEntity> possibleSpawns = ObfuscationReflectionHelper
|
||||
.getPrivateValue(AbstractSpawner.class, spawner, "field_98285_e");
|
||||
if (possibleSpawns.isEmpty()) {
|
||||
possibleSpawns = new ArrayList<>();
|
||||
possibleSpawns.add(
|
||||
ObfuscationReflectionHelper.getPrivateValue(AbstractSpawner.class, spawner, "field_98282_f"));
|
||||
}
|
||||
for (WeightedSpawnerEntity e : possibleSpawns) {
|
||||
if (new ResourceLocation(e.getNbt().getString("id")).equals(EntityType.BLAZE.getRegistryName())) {
|
||||
ItemStack itemWithBlaze = withBlaze(context.getItem());
|
||||
context.getItem()
|
||||
.shrink(1);
|
||||
dropOrPlaceBack(context.getWorld(), context.getPlayer(), itemWithBlaze);
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.onItemUse(context);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue