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

[1.14.3] Confused about custom glass


kwpugh
 Share

Recommended Posts

Hi All,

 

I'm trying to create a custom glass block.

 

Here is the basic code:

package com.kwpugh.gobber2.blocks;

import net.minecraft.block.GlassBlock;

public class BlockGobberGlass extends GlassBlock
{

	public BlockGobberGlass(Properties properties)
	{
		super(properties);
	}

}

I thought that creating a block that extends GlassBlock would give my glass block all of the properties of its parent and above, such as being transparent, which it is not.   The sides are black.

 

In Game Result

 

Any thoughts on what I'm doing wrong here?

 

Regards.

Link to comment
Share on other sites

Check also what properties are being passed to the vanilla block's constructor.

 

Oh and if you're going to do fuckall custom code,  you don't need your own class. Just call new on GlassBlock directly.

Edited by Draco18s

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.

Link to comment
Share on other sites

I'm going to add custom methods that allow players to walk through but no mobs.   Also, a higher tier of the glass with prohibit spider climbing and be wither proof.   I kept my post simple because the basics were not working the way they did in my 1.12.2 code.

 

I found the problem, I was not calling the correct "new BlockGobberGlass" .

 

 

 

 

Link to comment
Share on other sites

Hi,

 

In 1.12.2, I was using AxisAlignedBB for working with collision boxes on my glass.   Should I be using VoxelShapes in 1.14.3?

 

If yes, are there any documents on the basics of VoxelShapes?   I have been looking through the reference source and I am not really understanding it.

 

Question: I presume that instances of GlassBlock have a solid collision box?   I'm trying to make that conditional, depending on the entity type colliding with it?  How does one remove the collision box on a block?

 

Thank you in advance.

 

Regards.

 

Link to comment
Share on other sites

  • 2 weeks later...
On 7/2/2019 at 1:59 AM, kwpugh said:

Should I be using VoxelShapes in 1.14.3?

Yes

On 7/2/2019 at 1:59 AM, kwpugh said:

If yes, are there any documents on the basics of VoxelShapes?

You can create them with VoxelShapes.create.

unknown.thumb.png.9fc8bb10d23247b25e7f2d2d93a9f704.png

On 7/2/2019 at 1:59 AM, kwpugh said:

I presume that instances of GlassBlock have a solid collision box?

Yes

On 7/2/2019 at 1:59 AM, kwpugh said:

I'm trying to make that conditional, depending on the entity type colliding with it?

You can do it by checking the entity in the context passed into getCollisionShape.

On 7/2/2019 at 1:59 AM, kwpugh said:

How does one remove the collision box on a block?

return VoxelShapes.empty() from getCollisionShape or calling doesNotBlockMovement on the Block.Properties you pass in to your block.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

5 hours ago, kwpugh said:

does getCollisionShape replace the deprecated onEntityCollision

No

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

Hello Again,

 

I am still trying work through this.   I found that the LilyPadBlock class still uses the onEntityCollison, so I started to pattern my custom glass block on that.

 

It is not working.   I suspect that I am not fully understanding exactly how VoxelShapes work.

 

Here is my current class for a custom glass block.

 

package com.kwpugh.gobber2.blocks;

import java.util.List;

import javax.annotation.Nullable;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.GlassBlock;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

public class BlockGobberGlass extends GlassBlock
{
	public BlockGobberGlass(Properties properties)
	{
		super(properties);
	}
	
	
	@SuppressWarnings("deprecation")
	public void onEntityCollision(BlockState state, World worldIn, BlockPos pos, Entity entityIn)
	 {
		ISelectionContext context = (ISelectionContext) entityIn;
	      super.onEntityCollision(state, worldIn, pos, entityIn);
	      
		  entityIn.sendMessage(new StringTextComponent("Collision occured"));
		  getShape(state, worldIn, pos, context);
	 }
	 
	public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context)
	{
		if(context instanceof PlayerEntity)
		{
			return VoxelShapes.empty();
		}
		else
		{
			return VoxelShapes.fullCube();
		} 
	}
	
	@OnlyIn(Dist.CLIENT)
	public void addInformation(ItemStack stack, @Nullable IBlockReader world, List<ITextComponent> tooltip, ITooltipFlag flag)
	{
		super.addInformation(stack, world, tooltip, flag);				
		tooltip.add(new StringTextComponent(TextFormatting.BLUE + "A very sturdy glass block"));
		tooltip.add(new StringTextComponent(TextFormatting.GREEN + "Drops the block when broken"));
	}
}

 

Please keep in mind that I am pretty new to Java and continue to work my way through a large Udemy course (77+ hours).

 

Big question:  I am not quite clear about the relationship between AxisAlignedBB and VoxelShapes.

- Which one actually controls the properties of a given block's bounding box.   

- What is the difference between a block's bounding box and collision box?   Is there a difference?

- is a return of VoxelShapes.empty() and VoxelShapes.fullCube() intended to have an empty BB and a full BB respectively?

- Am I using the selectionContext interface correctly?

 

Thank you in advance for any guidance.

 

Regards.

 

[EDIT] I am also confused by when to use VoxelShape and VoxelShapes.

 

Edited by kwpugh
Link to comment
Share on other sites

Ok, so I actually got it working as I wanted, but it seems like a very contrived way to accomplished it.   Feedback to simplify are welcome.

 

package com.kwpugh.gobber2.blocks;

import java.util.List;

import javax.annotation.Nullable;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.GlassBlock;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

public class BlockGobberGlass extends GlassBlock
{
	public BlockGobberGlass(Properties properties)
	{
		super(properties);
	}
	
	public static final VoxelShape GLASS_NOT_SOLID_AABB = Block.makeCuboidShape(0.0D, 0.0D, 0.00D, 0.0D, 0.0D, 0.0D);
	public static final VoxelShape GLASS_SOLID_AABB = Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D);	
	
	public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context)
	{			
		if(   (context.getEntity() instanceof PlayerEntity) && (context.getEntity().isSneaking()) )
		{
			return GLASS_SOLID_AABB;
		}
		
		if(context.getEntity() instanceof PlayerEntity)       
		{
			return GLASS_NOT_SOLID_AABB;
		}
		else     
		{
			return GLASS_SOLID_AABB;
		}  
    }

	public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context)
	{
		if(   (context.getEntity() instanceof PlayerEntity) && (context.getEntity().isSneaking()) )
		{
			return GLASS_SOLID_AABB;
		}
		
		if(context.getEntity() instanceof PlayerEntity)
		{
			return GLASS_NOT_SOLID_AABB;
		}
		else
		{
			return GLASS_SOLID_AABB;
		}
	}

	public void onEntityCollision(BlockState state, World worldIn, BlockPos pos, Entity entityIn)
	{
		//entityIn.attackEntityFrom(DamageSource.CACTUS, 1.0F);
	}

	@OnlyIn(Dist.CLIENT)
	public void addInformation(ItemStack stack, @Nullable IBlockReader world, List<ITextComponent> tooltip, ITooltipFlag flag)
	{
		super.addInformation(stack, world, tooltip, flag);				
		tooltip.add(new StringTextComponent(TextFormatting.BLUE + "A very sturdy glass block"));
		tooltip.add(new StringTextComponent(TextFormatting.GREEN + "Drops the block when broken"));
	}
}

 

My question now is how to conditionally change block properties (ex. if entity is a spider then setBesideClimbableBlock to false).

 

 

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

    • Oh, Now that I see it better the error is different.  This is the error now i dont saw much of it: 2022-01-19 21:36:34,998 main WARN Advanced terminal features are not available in this environment [21:36:36] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.2.22, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge] [21:36:36] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 8.0.9+86+master.3cf110c starting: java version 1.8.0_25 by Oracle Corporation [21:36:36] [main/WARN] [cp.mo.mo.SecureJarHandler/]: LEGACY JDK DETECTED, SECURED JAR HANDLING DISABLED [21:36:38] [main/INFO] [ne.mi.fm.lo.FixSSL/CORE]: Added Lets Encrypt root certificates as additional trust [21:36:38] [main/INFO] [mixin/]: SpongePowered MIXIN Subsystem Version=0.8.4 Source=file:/C:/Users/Lautaro/Desktop/server1/libraries/org/spongepowered/mixin/0.8.4/mixin-0.8.4.jar Service=ModLauncher Env=SERVER Exception in thread "main" [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: jdk/nashorn/api/scripting/ClassFilter [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at net.minecraftforge.coremod.NashornFactory.createEngine(NashornFactory.java:13) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at net.minecraftforge.coremod.CoreModEngine.loadCoreMod(CoreModEngine.java:52) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at net.minecraftforge.coremod.CoreModProvider.addCoreMod(CoreModProvider.java:12) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at net.minecraftforge.fml.loading.LoadingModList$$Lambda$347/589987187.accept(Unknown Source) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:270) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:512) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at net.minecraftforge.fml.loading.LoadingModList.addCoreMods(LoadingModList.java:85) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at net.minecraftforge.fml.loading.moddiscovery.ModDiscoverer.discoverMods(ModDiscoverer.java:130) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at net.minecraftforge.fml.loading.FMLLoader.beginModScan(FMLLoader.java:216) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at net.minecraftforge.fml.loading.FMLServiceProvider.runScan(FMLServiceProvider.java:107) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at cpw.mods.modlauncher.TransformationServiceDecorator.runScan(TransformationServiceDecorator.java:114) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at cpw.mods.modlauncher.TransformationServicesHandler.lambda$runScanningTransformationServices$8(TransformationServicesHandler.java:115) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at cpw.mods.modlauncher.TransformationServicesHandler$$Lambda$185/259564670.apply(Unknown Source) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:267) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1612) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:512) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at cpw.mods.modlauncher.TransformationServicesHandler.runScanningTransformationServices(TransformationServicesHandler.java:116) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at cpw.mods.modlauncher.TransformationServicesHandler.initializeTransformationServices(TransformationServicesHandler.java:63) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at cpw.mods.modlauncher.Launcher.run(Launcher.java:76) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at net.minecraftforge.server.ServerMain$Runner.runLauncher(ServerMain.java:63) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at net.minecraftforge.server.ServerMain$Runner.access$100(ServerMain.java:60) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:       at net.minecraftforge.server.ServerMain.main(ServerMain.java:57) [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1061]: Caused by: java.lang.NoClassDefFoundError: jdk/nashorn/api/scripting/ClassFilter [21:36:39] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1061]:       ... 38 more [21:36:39] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:643]: Caused by: java.lang.ClassNotFoundException: jdk.nashorn.api.scripting.ClassFilter [21:36:39] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:643]:    at java.net.URLClassLoader$1.run(URLClassLoader.java:372) [21:36:39] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:643]:    at java.net.URLClassLoader$1.run(URLClassLoader.java:361) [21:36:39] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:643]:    at java.security.AccessController.doPrivileged(Native Method) [21:36:39] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:643]:    at java.net.URLClassLoader.findClass(URLClassLoader.java:360) [21:36:39] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:643]:    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) [21:36:39] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:643]:    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) [21:36:39] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:643]:    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) [21:36:39] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:643]:    ... 38 more
    • i tried that but it says the same error
    • No, and it is in fact broken. Firstly, you never register this type, so it will never work correctly. Secondly, you must not create registry entries in static initializers. You did it correctly above: Use this instead. However this is in the wrong class, as particle types (as all registry entries) must be registered on both sides (client and server). As such doing this in a client-only class will never work right.
    • Every time you post you post in the wrong subforum and I have to move your thread. Please take the hint. This is broken. You must not return null from this method. Use NetworkHooks.getEntitySpawningPacket. You must also only spawn your entity and start riding it on the server.
    • Sorry about the wait, I managed to fix the issue by loading in one of my server providers presets and stealing the jar from that. Sorry about wasting your time.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.