Jump to content

Disable XP spawned from a mod spawner


TheSgtPunishment

Recommended Posts

I'm one of the members of Soul Shards: The Old Ways dev team and I'm trying to work how to prevent mobs spawned via the soul cages dropping xp when killed, here is the current code in the cagetile class

 

 

package sstow.gameObjs.tile;

import java.util.List;

import sstow.gameObjs.ObjHandler;
import sstow.utils.EntityMapper;
import sstow.utils.Config;
import sstow.utils.TOWLogger;
import sstow.utils.TierHandler;
import sstow.utils.Utils;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.entity.monster.EntityMagmaCube;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.EntityPigZombie;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.monster.EntitySlime;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.passive.IAnimals;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;

public class CageTile extends TileEntity implements ISidedInventory {
private ItemStack inventory;
private int counter;
private int updateCounter;
private int tier;
private static final int[] slot = new int[] { 0, 1, 2, 3, 4, 5 };
private String entName;
private boolean redstoneActive;
private boolean initChecks;
private boolean active;

public CageTile() {
	counter = 0;
	updateCounter = 0;
	redstoneActive = false;
	initChecks = false;
	active = false;
}

@Override
public void updateEntity() {
	if (worldObj.isRemote) {
		return;
	}
	this.worldObj.func_147453_f(this.xCoord, this.yCoord, this.zCoord,
			ObjHandler.SOUL_CAGE);
	if (!initChecks) {
		checkRedstone();
		initChecks = true;
	}

	if (this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 0
			|| tier <= 0) {
		updateCounter = 0;
		counter = 0;
		return;
	}

	if (updateCounter == 19) {
		EntityLiving ent = EntityMapper.getNewEntityInstance(this.worldObj,
				entName);

		if (canEntitySpawn(ent)) {
			setMetadata(2);
			active = true;
		} else {
			setMetadata(1);
			active = false;
		}
		updateCounter = 0;
	} else {
		updateCounter += 1;
	}

	if (this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord) <= 1) {
		counter = 0;
		return;
	}

	if (counter >= TierHandler.getCooldown(tier - 1) * 20 - 1) {
		if (Config.ENABLE_DEBUG) {
			TOWLogger.logDebug("SPAWNING!");
		}
		EntityLiving[] toSpawn = new EntityLiving[TierHandler
				.getNumSpawns(tier - 1)];

		ItemStack heldItem = Utils.getEntityHeldItem(inventory);
		for (int i = 0; i < toSpawn.length; i++) {
			toSpawn[i] = EntityMapper.getNewEntityInstance(this.worldObj,
					entName);

			if ((toSpawn[i] instanceof EntitySlime)) {
				toSpawn[i].getDataWatcher().updateObject(16,
						Byte.valueOf((byte) 1));
			}

			if (heldItem != null) {
				toSpawn[i].setCurrentItemOrArmor(0, heldItem);
			}

			for(int j=1;j<=4;j++){
				toSpawn[i].setCurrentItemOrArmor(j, Utils.getEntityArmor(inventory, j));
			}

			toSpawn[i].getEntityData().setBoolean("SSTOW", true);

			toSpawn[i].forceSpawn = true;
			toSpawn[i].func_110163_bv();
		}
		spawnEntities(toSpawn);
		counter = 0;
	} else {
		counter += 1;
	}
}

public void checkRedstone() {
	if (worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord,
			this.zCoord)) {
		redstoneActive = true;
	} else {
		redstoneActive = false;
	}
}

private void setMetadata(int meta) {
	if (this.worldObj.getBlockMetadata(this.xCoord, this.yCoord,
			this.zCoord) != meta) {
		this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord,
				this.zCoord, meta, 2);
	}
}

private boolean canEntitySpawn(EntityLiving ent) {
	if ((Config.ENABLE_FLOOD_PREVENTION) && (hasReachedSpawnLimit(ent))) {
		return false;
	}

	if ((TierHandler.getChecksRedstone(tier - 1))
			&& (redstoneActive == Config.INVERT_REDSTONE)) {
		return false;
	}

	if ((TierHandler.getChecksPlayer(tier - 1))
			&& (!isPlayerClose(this.xCoord, this.yCoord, this.zCoord))) {
		return false;
	}

	if ((TierHandler.getChecksLight(tier - 1)) && (!canSpawnInLight(ent))) {
		return false;
	}

	if ((TierHandler.getChecksWorld(tier - 1)) && (!canSpawnInWorld(ent))) {
		return false;
	}
	return true;
}

private boolean isPlayerClose(int x, int y, int z) {
	return worldObj.getClosestPlayer(x, y, z, 16.0D) != null;
}

private boolean canSpawnInWorld(EntityLiving ent) {
	int dimension = worldObj.provider.dimensionId;

	if ((ent instanceof EntitySkeleton)) {
		EntitySkeleton skele = (EntitySkeleton) ent;

		if ((skele.getSkeletonType() == 1) && (dimension == -1)) {
			return true;
		}
		if (dimension == 0) {
			return true;
		}
		return false;
	}

	if (((ent instanceof EntityBlaze))
			|| ((ent instanceof EntityPigZombie))
			|| ((ent instanceof EntityGhast))
			|| ((ent instanceof EntityMagmaCube))) {
		return dimension == -1;
	}
	if ((ent instanceof EntityEnderman)) {
		return dimension == 1;
	}
	return true;
}

private boolean canSpawnInLight(EntityLiving ent) {
	int light = worldObj.getBlockLightValue(xCoord, yCoord, zCoord);
	if (((ent instanceof EntityMob)) || ((ent instanceof IMob))) {
		return light <= 8;
	}
	if (((ent instanceof EntityAnimal)) || ((ent instanceof IAnimals))) {
		return light > 8;
	}
	return true;
}

private boolean canSpawnAtCoords(EntityLiving ent) {
	return worldObj.getCollidingBoundingBoxes(ent, ent.boundingBox)
			.isEmpty();
}

private boolean hasReachedSpawnLimit(EntityLiving ent) {
	AxisAlignedBB aabb = AxisAlignedBB
			.getBoundingBox(xCoord - 16, yCoord - 16, zCoord - 16,
					xCoord + 16, yCoord + 16, zCoord + 16);
	int mobCount = 0;

	for (EntityLiving entity : (List<EntityLiving>) worldObj
			.getEntitiesWithinAABB(ent.getClass(), aabb)) {
		if (entity.getEntityData().getBoolean("SSTOW")) {
			mobCount++;
		}
	}
	return mobCount >= Config.MAX_NUM_ENTITIES;
}

private void spawnEntities(EntityLiving[] ents) {
	for (EntityLiving ent : ents) {
		int counter = 0;
		do {
			counter++;
			if (counter >= 5) {
				ent.setDead();
				break;
			}
			double x = xCoord
					+ (worldObj.rand.nextDouble() - worldObj.rand
							.nextDouble()) * 4.0D;
			double y = yCoord + worldObj.rand.nextInt(3) - 1;
			double z = zCoord
					+ (worldObj.rand.nextDouble() - worldObj.rand
							.nextDouble()) * 4.0D;
			ent.setLocationAndAngles(x, y, z,
					worldObj.rand.nextFloat() * 360.0F, 0.0F);
		} while (!canSpawnAtCoords(ent) || counter >= 5);
		if (!ent.isDead) {
			worldObj.spawnEntityInWorld(ent);
		}
	}
}

public void invalidate() {
	super.invalidate();
	initChecks = false;
}

public void readFromNBT(NBTTagCompound nbt) {
	super.readFromNBT(nbt);

	inventory = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("Shard"));
	if (inventory != null) {
		tier = Utils.getShardTier(inventory);
		entName = Utils.getShardBoundEnt(inventory);
	}
	active = nbt.getBoolean("active");
}

public void writeToNBT(NBTTagCompound nbt) {
	super.writeToNBT(nbt);
	if (inventory != null) {
		NBTTagCompound tag = new NBTTagCompound();
		inventory.writeToNBT(tag);
		nbt.setTag("Shard", tag);
	}
	nbt.setBoolean("active", active);
}

public int getSizeInventory() {
	return 0;
}

public ItemStack getStackInSlot(int slot) {
	return inventory;
}

public ItemStack decrStackSize(int slot, int qty) {
	if (qty == 0) {
		return null;
	}
	ItemStack stack = inventory.copy();
	inventory = null;

	this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 2);
	this.tier = 0;
	this.entName = null;

	return stack;
}

public void setInventorySlotContents(int slot, ItemStack stack) {
	this.inventory = stack;

	this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord,
			this.zCoord, 1, 2);
	this.tier = Utils.getShardTier(this.inventory);
	this.entName = Utils.getShardBoundEnt(this.inventory);
}

@Override
public ItemStack getStackInSlotOnClosing(int slot) {
	return null;
}

@Override
public String getInventoryName() {
	return null;
}

@Override
public boolean hasCustomInventoryName() {
	return false;
}

@Override
public int getInventoryStackLimit() {
	return 1;
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	return false;
}

@Override
public void openInventory() {
}

@Override
public void closeInventory() {
}

public int getTier() {
	return tier;
}

public String getEntityName() {
	return entName;
}

@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
	return stack != null && stack.getItem() == ObjHandler.SOUL_SHARD
			&& Utils.isShardBound(stack) && Utils.getShardTier(stack) > 0;
}

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
	this.readFromNBT(pkt.func_148857_g());
	this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}

@Override
public Packet getDescriptionPacket() {
	NBTTagCompound tag = new NBTTagCompound();
	this.writeToNBT(tag);
	return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord,
			this.zCoord, 0, tag);
}

@Override
public int[] getAccessibleSlotsFromSide(int var1) {

	return var1 == 0 ? slot : (var1 == 1 ? slot : slot);
}

@Override
public boolean canInsertItem(int var1, ItemStack stack, int p_102007_3_) {
	return this.isItemValidForSlot(var1, stack);
}

@Override
public boolean canExtractItem(int p_102008_1_, ItemStack p_102008_2_,
		int p_102008_3_) {

	return true;
}
}

 

 

As you can see, there's two spots that we tag mobs spawned from the cages with "SSTOW" that is to let the soul stealer enchantment from this mod not to count those mob kills towards a shard total, but you still get xp from said mobs, how do I disable it? I found a protected int by the name "getExperiancePoints" but I can't access it (Or at least my knowledge of coding is very limited and I don't know of a method to access it), so any help would be greatly appreciated

 

tl;dr I want to stop mobs spawned with soul cages dropping xp on death

Link to comment
Share on other sites

On a side note: I see no reason why the spawned mobs shouldn't be able to drop experience. This makes soul shards useless for experience spawners. If it's balancing that you're worried about, start by nerfing tier 5 spawners.

 

People are using soul shards for inf mob essence with minefactory reloaded, and currently there's no api to tap into to prevent grinders producing mob essence

Link to comment
Share on other sites

On a side note: I see no reason why the spawned mobs shouldn't be able to drop experience. This makes soul shards useless for experience spawners. If it's balancing that you're worried about, start by nerfing tier 5 spawners.

 

People are using soul shards for inf mob essence with minefactory reloaded, and currently there's no api to tap into to prevent grinders producing mob essence

 

I'm not seeing the problem. Let people play how they want. No need to police your playerbase.

Link to comment
Share on other sites

On a side note: I see no reason why the spawned mobs shouldn't be able to drop experience. This makes soul shards useless for experience spawners. If it's balancing that you're worried about, start by nerfing tier 5 spawners.

 

People are using soul shards for inf mob essence with minefactory reloaded, and currently there's no api to tap into to prevent grinders producing mob essence

 

I'm not seeing the problem. Let people play how they want. No need to police your playerbase.

 

You might not see a problem, but this is an exploit and needs to be fixed.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.