Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.11.2]Detection of Liquid


Villfuk02
 Share

Recommended Posts

I have in my code this line:

if (!(block instanceof BlockLiquid)){

while the block is block the player is currently standing in
 

Block block = worldIn.getBlockState(player.getPosition()).getBlock();

and i'm trying to test if the player is standing in any liquid for example water/lava/oil...

It seems to work, but only server-side not client-side :( and only on vanilla liquids - lava and water

with liquids from other mods it doesn't detect liquid at all
 

please hep me
thanks

Edited by Villfuk02
Link to comment
Share on other sites

@Override
	public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
		ItemStack stack = player.getHeldItem(hand);
		IDetector detector = stack.getCapability(DetectorProvider.DETECTOR_CAP, null);
		detector.setFound(false);
		Block block = worldIn.getBlockState(player.getPosition()).getBlock();
		int x = 0;
		int y = 0;
		int z = 0;
		if (!(block instanceof BlockLiquid)){
			Utils.getLogger().info("No Liquid");
				int batteryMulti = 0;
				int coilMulti = 0;
				int rodMulti = 0;
				int displayMulti = 0;
				if (stack.getItemDamage() < maxDamage - 2500){					
					switch(detector.getCoil()){
					case 0:						
						Scan(pos, worldIn, false, stack, generateScan(-1, 1, 1, generateScan(0, 1, 2)));
						break;
					case 1:					
						Scan(pos, worldIn, false, stack, generateScan(-2, 0, 0,generateScan(-1, 1, 2,generateScan(0, 2, 3))));
						break;
					case 2:						
						Scan(pos, worldIn, false, stack, generateScan(-2, 1, 2,generateScan(-1, 2, 3,generateScan(0, 3, 4))));
						break;
					case 3:					
						Scan(pos, worldIn, false, stack,generateScan(-2, 1, 2,generateScan(-1, 2, 3,generateScan(0, 2, 3,generateScan(1, 2, 3,generateScan(2, 1, 2))))));
						break;
					case 4:					
						Scan(pos, worldIn, true, stack, generateScan(-2, 0, 0,generateScan(-1, 1, 2,generateScan(0, 2, 3))));
						break;
					case 5:
						Scan(pos, worldIn, false, stack, generateScan(-5, 0, 0,generateScan(-4, 1, 1,generateScan(-3, 1, 1,generateScan(-2, 1, 2,generateScan(-1, 1, 2,generateScan(0, 1, 2)))))));
						break;
					}
					if(detector.getBattery() < BatteryTypes.values().length)
						batteryMulti = BatteryTypes.values()[detector.getBattery()].getMulti();
					if(detector.getRod() < RodTypes.values().length)
						rodMulti = RodTypes.values()[detector.getRod()].getMulti();
					if(detector.getCoil() < CoilTypes.values().length)
						coilMulti = CoilTypes.values()[detector.getCoil()].getMulti();
					if(detector.getDisplay() < DisplayTypes.values().length)
						displayMulti = DisplayTypes.values()[detector.getDisplay()].getMulti();
					
					stack.damageItem((batteryMulti * coilMulti * rodMulti * displayMulti) / efficiency, player);
					
										
					if (detector.getIntegrity() > 2000)
						detector.setIntegrity(detector.getIntegrity() -(((detector.getIntegrity() - 2000) * RodTypes.values()[detector.getRod()].getIntegrity()) / (use_integrity_divider * 5)));
					
					
					
				} else {
					stack.damageItem(maxDamage - stack.getItemDamage(), player);
				}	
		} else {
			Utils.getLogger().info("Liquid");
		}
		return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
	} 
	
	
	
	public List<BlockPos> generateScan(int y, int radius, int max){
		List<BlockPos> modifiers = new ArrayList();
		for(int x = 0 - radius; x <= radius; x++){
			for(int z = 0 - radius; z <= radius; z++){
				if(Math.abs(x) + Math.abs(z) <= max)
					modifiers.add(new BlockPos(x, y, z));
			}
		}
		return modifiers;
	}
	public List<BlockPos> generateScan(int y, int radius, int max, List<BlockPos> modifiers){
		for(int x = 0 - radius; x <= radius; x++){
			for(int z = 0 - radius; z <= radius; z++){
				if(Math.abs(x) + Math.abs(z) <= max)
					modifiers.add(new BlockPos(x, y, z));
			}
		}
		return modifiers;
	}
	
	public void Scan(BlockPos pos, World world, Boolean ultraSound, ItemStack stack, List<BlockPos> modifiers){
		IDetector detector = stack.getCapability(DetectorProvider.DETECTOR_CAP, null);
		for (int i = 0; i < modifiers.size(); i++) {
			BlockPos scanBlock = new BlockPos(pos.getX() + modifiers.get(i).getX(), pos.getY() + modifiers.get(i).getY(), pos.getZ() + modifiers.get(i).getZ());
			if (world.getBlockState(scanBlock).getBlock().equals(ModBlocks.archeology_dirt)){	
				if(ultraSound && ArcheologyDirt.getIntFromState(world.getBlockState(scanBlock)) != 0 && ArcheologyDirt.getIntFromState(world.getBlockState(scanBlock)) != 14){
					detector.setFound(true);
					detector.setDistance(scanBlock.distanceSqToCenter(pos.getX(), pos.getY(), pos.getZ()));
					detector.setType(EnumHandler.Types.getTypeId(ArcheologyDirt.getTypeFromMeta(ArcheologyDirt.getIntFromState((world.getBlockState(scanBlock))))));
					detector.setDirection(getDirection(modifiers.get(i)));
					
				} else if(ArcheologyDirt.getMetalFromMeta(ArcheologyDirt.getIntFromState(world.getBlockState(scanBlock)))){
					detector.setFound(true);
					detector.setDistance(scanBlock.distanceSqToCenter(pos.getX(), pos.getY(), pos.getZ()));
					detector.setType(EnumHandler.Types.getTypeId(ArcheologyDirt.getTypeFromMeta(ArcheologyDirt.getIntFromState((world.getBlockState(scanBlock))))));
					detector.setDirection(getDirection(modifiers.get(i)));
				}
			}
		}
	}

 

Here's the method i call the check in, hope you can find something

Link to comment
Share on other sites

I suspect you're running into the discrepancy between EntityPlayerMP#getPosition and EntityPlayerSP#getPosition. The former adds 0.5 to the y coordinate and uses the x and z coordinates as-is, but the latter adds 0.5 to every coordinate. I don't really know why Mojang chose to do this.

 

You'll likely want to use the BlockPos(Entity) constructor instead, this won't add any offsets to the entity's coordinates.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • But Forge defiently glitch the Minecraft launcher. Ever since I had Forge. I couldn't access bedrock.
    • Sorry. I guess it's outside Forge than. The Xbox App isn't working. And I can only play only via Java.
    • Hello, I am trying to launch a mod pack i made for forge 1.12.2 but every time I launch the pack it fails with exit code 1.   crash log: https://pastebin.com/06SkS9CF debug log: https://pastebin.com/2k7jxBqb
    • I'm trying to sync player capabilities from server to client using packets. I've researched about this topic a lot, but man is it confusing. I'm trying to update the players data on the client side when the player logs in, respawns, and when they change dimension. I also do so with the event StartTracking. Here are those events: @SubscribeEvent public void onPlayerTracking(PlayerEvent.StartTracking event) { if(event.getTarget() instanceof PlayerEntity) { PlayerEntity player = (PlayerEntity)event.getTarget(); ServerPlayerEntity target = (ServerPlayerEntity)event.getPlayer(); if(!player.getCommandSenderWorld().isClientSide()) { player.getCapability(TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY).ifPresent(capability -> { CompoundNBT nbt = new CompoundNBT(); Capability<ITitanShifters> cap = TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY; Capability.IStorage<ITitanShifters> storage = cap.getStorage(); nbt.put(cap.getName(), storage.writeNBT(cap, capability, TitanShiftersMod.direction)); ClientMessage message = new ClientMessage(nbt); TitanShiftersNetwork.CLIENTCHANNEL.send(PacketDistributor.PLAYER.with(() -> target), message); }); } } } @SubscribeEvent public void onPlayerLogin(PlayerLoggedInEvent event) { ServerPlayerEntity player = (ServerPlayerEntity)event.getPlayer(); if(!player.getCommandSenderWorld().isClientSide()) { player.getCapability(TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY).ifPresent(capability -> { CompoundNBT nbt = new CompoundNBT(); Capability<ITitanShifters> cap = TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY; Capability.IStorage<ITitanShifters> storage = cap.getStorage(); nbt.put(cap.getName(), storage.writeNBT(cap, capability, TitanShiftersMod.direction)); ClientMessage message = new ClientMessage(nbt); TitanShiftersNetwork.CLIENTCHANNEL.send(PacketDistributor.PLAYER.with(() -> player), message); }); } } @SubscribeEvent public void onPlayerRespawn(PlayerRespawnEvent event) { ServerPlayerEntity player = (ServerPlayerEntity)event.getPlayer(); if(!player.getCommandSenderWorld().isClientSide()) { player.getCapability(TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY).ifPresent(capability -> { CompoundNBT nbt = new CompoundNBT(); Capability<ITitanShifters> cap = TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY; Capability.IStorage<ITitanShifters> storage = cap.getStorage(); nbt.put(cap.getName(), storage.writeNBT(cap, capability, TitanShiftersMod.direction)); ClientMessage message = new ClientMessage(nbt); TitanShiftersNetwork.CLIENTCHANNEL.send(PacketDistributor.PLAYER.with(() -> player), message); }); } } @SubscribeEvent public void onPlayerChangeDimension(PlayerChangedDimensionEvent event) { ServerPlayerEntity player = (ServerPlayerEntity)event.getPlayer(); if(!player.getCommandSenderWorld().isClientSide()) { player.getCapability(TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY).ifPresent(capability -> { CompoundNBT nbt = new CompoundNBT(); Capability<ITitanShifters> cap = TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY; Capability.IStorage<ITitanShifters> storage = cap.getStorage(); nbt.put(cap.getName(), storage.writeNBT(cap, capability, TitanShiftersMod.direction)); ClientMessage message = new ClientMessage(nbt); TitanShiftersNetwork.CLIENTCHANNEL.send(PacketDistributor.PLAYER.with(() -> player), message); }); } } Here is the packet I am sending: public class ClientMessage { private CompoundNBT data; public ClientMessage(CompoundNBT d) { data = d; } public static void encode(ClientMessage message, PacketBuffer buffer) { buffer.writeNbt(message.data); } public static ClientMessage decode(PacketBuffer buffer) { return new ClientMessage(buffer.readNbt()); } public static void handle(ClientMessage message, Supplier<NetworkEvent.Context> supplier) { NetworkEvent.Context context = supplier.get(); context.enqueueWork(() -> { if(context.getDirection().getReceptionSide().isClient() && context.getDirection().getOriginationSide().isServer()) { @SuppressWarnings("resource") ClientPlayerEntity p = Minecraft.getInstance().player; p.getEntity().getCapability(TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY).ifPresent(capability -> { Capability.IStorage<ITitanShifters> storage = TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY.getStorage(); storage.readNBT(TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY, capability, TitanShiftersMod.direction, message.data); }); } }); context.setPacketHandled(true); } } Here is my network class: (I made two networks for sending packets to server and to client) public class TitanShiftersNetwork { private static int id = 0; public static final String NETWORK_VERSION = "0.1.0"; private static ResourceLocation loc = new ResourceLocation(TitanShiftersMod.MOD_ID, "network"); private static ResourceLocation Clientloc = new ResourceLocation(TitanShiftersMod.MOD_ID, "networkclient"); public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel(loc, () -> NETWORK_VERSION, version -> version.equals(NETWORK_VERSION), version -> version.equals(NETWORK_VERSION)); public static final SimpleChannel CLIENTCHANNEL = NetworkRegistry.ChannelBuilder.named(Clientloc).clientAcceptedVersions(s -> Objects.equals(s, "1")) .serverAcceptedVersions(s -> Objects.equals(s, "1")).networkProtocolVersion(() -> "1").simpleChannel(); public static void init() { CHANNEL.registerMessage(0, InputMessage.class, InputMessage::encode, InputMessage::decode, InputMessage::handle); CLIENTCHANNEL.messageBuilder(ClientMessage.class, id++).decoder(ClientMessage::decode).encoder(ClientMessage::encode).consumer(ClientMessage::handle).add(); } } Here is where the Init() method is being called: @SubscribeEvent public void commonSetup(final FMLCommonSetupEvent event) { TitanShiftersNetwork.init(); } And here is where I am trying to update the data on the client side: public static void InheritAttack(PlayerEntity player) { LazyOptional<ITitanShifters> titan = player.getCapability(TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY, TitanShiftersMod.direction); ITitanShifters titanShifter = titan.orElse(new TitanShifters()); TitanShiftersStats.setAttackTitan(true, player); pureUnshift(player); System.out.println(player.getScoreboardName() + " is pure titan: " + titanShifter.getPureTitan().toString()); ServerPlayerEntity p = (ServerPlayerEntity)player; if(!p.getCommandSenderWorld().isClientSide()) { p.getCapability(TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY).ifPresent(capability -> { CompoundNBT nbt = new CompoundNBT(); Capability<ITitanShifters> cap = TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY; Capability.IStorage<ITitanShifters> storage = cap.getStorage(); nbt.put(cap.getName(), storage.writeNBT(cap, capability, TitanShiftersMod.direction)); ClientMessage message = new ClientMessage(nbt); TitanShiftersNetwork.CLIENTCHANNEL.send(PacketDistributor.TRACKING_ENTITY_AND_SELF.with(() -> p), message); }); } System.out.println(player.getScoreboardName() + " has inherited the attack titan!"); } Rest of the code is here: https://github.com/TheDerpyParagon/TitanShiftersMod Any help is much appreciated!
    • When I downloaded forge and installed the client version it didn't make a extension so I went to the extension tab and tried to find it but it wasn't there I tried to download previous versions of it but they don't make an extension if someone could help that would be nice!
  • Topics

×
×
  • Create New...

Important Information

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