mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 12:20:11 +00:00
Added java highlights.
1 parent
6f448c22e7
commit
fe08738322
1 file changed
+13
-13
@@ -23,7 +23,7 @@ Whenever a new update of Minecraft is released, these patches are applied to the
|
||||
|
||||
#### While coding:
|
||||
- Prevent to add extra spaces/line breaks, even when there are already existing ones in the code between statements. Below is an example that comes from `net.minecraft.entity.item.EntityItem#attackEntityFrom(DamageSourc, float)`:
|
||||
```
|
||||
```java
|
||||
<snip>
|
||||
this.setBeenAttacked();
|
||||
this.health = (int)((float)this.health - p_70097_2_);
|
||||
@@ -38,8 +38,8 @@ return false;
|
||||
```
|
||||
Lets say we add an `if`-statement between `this.setBeenAttacked();` and `this.health = (int)((float)this.health - p_70097_2_);`. It seems that `if`-statements get extra spaces/line breaks in the original code. However, when contributing to a `java.patch`-file you should always try to keep the changes as minimal as possible.
|
||||
So, don't do:
|
||||
```
|
||||
<snip>
|
||||
```java
|
||||
//snip
|
||||
this.setBeenAttacked();
|
||||
++
|
||||
+ if(isCondition) return false;
|
||||
@@ -52,11 +52,11 @@ if (this.health <= 0)
|
||||
}
|
||||
|
||||
return false;
|
||||
<snip>
|
||||
//snip
|
||||
```
|
||||
But do:
|
||||
```
|
||||
<snip>
|
||||
```java
|
||||
//snip
|
||||
this.setBeenAttacked();
|
||||
++ if(isCondition) return false;
|
||||
this.health = (int)((float)this.health - p_70097_2_);
|
||||
@@ -67,12 +67,12 @@ if (this.health <= 0)
|
||||
}
|
||||
|
||||
return false;
|
||||
<snip>
|
||||
//snip
|
||||
```
|
||||
|
||||
- In spirit of the previous point: prevent to add more lines than necessary. If you can reduce your statement to one single line, please do so.
|
||||
Example here is an `if`-statement that could be written as follows to improve readability:
|
||||
```
|
||||
```java
|
||||
if((float)this.field_70291_e - p_70097_2_ <= 0.0F)
|
||||
{
|
||||
if(net.minecraftforge.common.ForgeHooks.onItemDeath(this, p_70097_1_))
|
||||
@@ -82,18 +82,18 @@ if((float)this.field_70291_e - p_70097_2_ <= 0.0F)
|
||||
}
|
||||
```
|
||||
However, to keep changes to `.java.patch`-files as minimal as possible. Try to write that statement to one single line:
|
||||
```
|
||||
```java
|
||||
if((float)this.field_70291_e - p_70097_2_ <= 0.0F && net.minecraftforge.common.ForgeHooks.onItemDeath(this, p_70097_1_)) return false;
|
||||
```
|
||||
- Prevent using imports and try using full qualifications in the code. Using imports will generate extra lines in patch-files which can be prevented. Imports that are already in the file are not your concern. Example below:
|
||||
```
|
||||
<snip>
|
||||
```java
|
||||
//snip
|
||||
import net.minecraft.otherimports
|
||||
import net.minecraftforge.event.GenericEvent
|
||||
import net.minecraftforge.otherimports
|
||||
<snip>
|
||||
//snip
|
||||
if (isCondition) MinecraftForge.EVENT_BUS.post(new GenericEvent());
|
||||
<snip>
|
||||
//snip
|
||||
```
|
||||
Instead try to code it as:
|
||||
```
|
||||
|
||||
Reference in new issue
Block a user