Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

The arrows that i fire from my tileentiy don't actually do damage. Is there a way to fix this?

 

Code File:

Spoiler

package merthew.mod.block.divinity.altar;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Nullable;

import merthew.mod.inventory.EobItemHandler;
import merthew.mod.util.handlers.packets.DivineAltarButtonMessage;
import merthew.mod.util.handlers.packets.PacketHandler;
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
import net.minecraft.dispenser.IBehaviorDispenseItem;
import net.minecraft.entity.projectile.EntityTippedArrow;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.MobEffects;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.potion.PotionEffect;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.registry.RegistryDefaulted;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler;

public class TileEntityAltar extends TileEntity implements ITickable{
	public static final RegistryDefaulted<Item, IBehaviorDispenseItem> DISPENSE_BEHAVIOR_REGISTRY = new RegistryDefaulted<Item, IBehaviorDispenseItem>(new BehaviorDefaultDispenseItem());
	
	private final EobItemHandler itemHandler;
	boolean isCheckStart;
	boolean isPressed;
	int ticksPressed;
	
    boolean rainOfDeath;
    int rainOfDeathTick;
	
	public enum Ritual {
		RAIN, CLEAR, RAIN_OF_DEATH
	}
	
	Map<ArrayList<Item>, Ritual> recipes = new HashMap<ArrayList<Item>, Ritual>();
	
	public TileEntityAltar() {
		super();
		itemHandler = new EobItemHandler(8);
		
		ArrayList<Item> rain = new ArrayList<Item>();
		for(int i = 0; i < 8; i ++) {
			rain.add(Items.WATER_BUCKET);
		}
		recipes.put(rain, Ritual.RAIN);
		
		ArrayList<Item> clear = new ArrayList<Item>();
		for(int i = 0; i < 8; i ++) {
			clear.add(Item.getItemFromBlock(Blocks.AIR));
		}
		recipes.put(clear, Ritual.RAIN_OF_DEATH);
	}

	@Override
	public void update() {
		if(isPressed) {
			ticksPressed ++;
		}
		
		if(ticksPressed >= 10) {
			isPressed = false;
			ticksPressed = 0;
		}
		
		if(isCheckStart) {
			System.out.println("Check Start is a go.");
			if(shouldStart()) {
				System.out.println("Should Start is a go.");
				ArrayList<Item> inputs = new ArrayList<Item>();
				inputs.add(itemHandler.getStackInSlot(0).getItem());
				inputs.add(itemHandler.getStackInSlot(1).getItem());
				inputs.add(itemHandler.getStackInSlot(2).getItem());
				inputs.add(itemHandler.getStackInSlot(3).getItem());
				inputs.add(itemHandler.getStackInSlot(4).getItem());
				inputs.add(itemHandler.getStackInSlot(5).getItem());
				inputs.add(itemHandler.getStackInSlot(6).getItem());
				inputs.add(itemHandler.getStackInSlot(7).getItem());
				Ritual r = recipes.get(inputs);
				System.out.println("Ritual: " + r);
				
				switch(r) {
				case RAIN:
					PacketHandler.INSTANCE.sendToServer(new DivineAltarButtonMessage(0));
		            break;
				case CLEAR:
					PacketHandler.INSTANCE.sendToServer(new DivineAltarButtonMessage(1));
					break;
				case RAIN_OF_DEATH:
					rainOfDeath = true;
					System.out.println("Starting rain of death.");
				}
			}
			isCheckStart = false;
		}
		
		//Rain of Death =================================================================================================
		if(rainOfDeath) {
			rainOfDeathTick ++;
			EntityTippedArrow e = new EntityTippedArrow(world, pos.getX()+.5, pos.getY()+1, pos.getZ()+.5);
			e.motionX = (Math.random()*4)-2;
			e.motionZ = (Math.random()*4)-2;
			e.motionY = 1.0F;
			world.spawnEntity(e);
			System.out.println("Fired arrow.");
		}
		if(rainOfDeathTick >= 20* 10) {
			rainOfDeath = false;
			rainOfDeathTick = 0;
		}
	}
	
	protected IBehaviorDispenseItem getBehavior(ItemStack stack)
    {
        return DISPENSE_BEHAVIOR_REGISTRY.getObject(stack.getItem());
    }
	
	private boolean shouldStart() {
		ArrayList<Item> inputs = new ArrayList<Item>();
		inputs.add(itemHandler.getStackInSlot(0).getItem());
		inputs.add(itemHandler.getStackInSlot(1).getItem());
		inputs.add(itemHandler.getStackInSlot(2).getItem());
		inputs.add(itemHandler.getStackInSlot(3).getItem());
		inputs.add(itemHandler.getStackInSlot(4).getItem());
		inputs.add(itemHandler.getStackInSlot(5).getItem());
		inputs.add(itemHandler.getStackInSlot(6).getItem());
		inputs.add(itemHandler.getStackInSlot(7).getItem());
		
		if(recipes.containsKey(inputs)) {
			System.out.println("Is a recipe");
			return true;
		}
		else {
			System.out.println("Not a recipe");
			return false;
		}
	}
	
	@Override
	public void readFromNBT(NBTTagCompound nbtTagCompound)
	{
		super.readFromNBT(nbtTagCompound);
		itemHandler.deserializeNBT(nbtTagCompound.getCompoundTag("ItemHandler"));
	}
	
	@Override
	public NBTTagCompound writeToNBT(NBTTagCompound nbtTagCompound)
	{
		super.writeToNBT(nbtTagCompound);
		nbtTagCompound.setTag("ItemHandler", itemHandler.serializeNBT());	
		return nbtTagCompound;
	}
	
	public EobItemHandler getItemHandler()
	{
		return itemHandler;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing)
	{
		if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
		{
			return (T) itemHandler;
		}

		return super.getCapability(capability, facing);
	}

	@Override
	public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing)
	{
		return false;
	}

	@Override
	public SPacketUpdateTileEntity getUpdatePacket()
	{
		return new SPacketUpdateTileEntity(pos, 0, getUpdateTag());
	}

	@Override
	public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt)
	{
		readFromNBT(pkt.getNbtCompound());
	}

	@Override
	public NBTTagCompound getUpdateTag()
	{
		return this.writeToNBT(new NBTTagCompound());
	}

	public void saveCraftingInfo(String text, boolean modeRecieved) {
		this.updateTile();
	}

	void updateTile(){
		world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 3);
		world.scheduleBlockUpdate(pos,this.getBlockType(),0,0);
		markDirty();
	}
}

 

In all honesty it is more than likely something obvious.

The seven became one and the one became two.

I believe you have to call a function top set the arrow's damage amount. 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

there is a function called setDamage but that doesn't seem to have done anything.

The seven became one and the one became two.

  • Author

This is how i create the arrow and fire it:

EntityTippedArrow e = new EntityTippedArrow(world, pos.getX()+.5, pos.getY()+1, pos.getZ()+.5);
e.motionX = (Math.random()*4)-2;
e.motionZ = (Math.random()*4)-2;
e.motionY = 1.0F;
world.spawnEntity(e);

The way the bow does it, it calls the shoot function, i also tried that but to no avail.

The seven became one and the one became two.

  • Author

Fixed it, had to have it run on the server. again, it was something dumb.

The seven became one and the one became two.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.